Skip to content

Commit e5a9e6d

Browse files
committed
Adding fixup and hack for Network.CookiePartitionKey type
1 parent 9c107ad commit e5a9e6d

File tree

9 files changed

+257
-116
lines changed

9 files changed

+257
-116
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016-2018 Kenneth Shaw
3+
Copyright (c) 2016-2024 Kenneth Shaw
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

fixup/fixup.go

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
// - add Error() method to `Runtime.ExceptionDetails` so that it can be used
3131
// as error.
3232
// - change `Network.Headers` type to map[string]interface{}.
33+
// - add special unmarshaler to `Network.CookiePartitionKey` type to handle
34+
// different versions.
3335
//
3436
// Please note that the above is not an exhaustive list of all modifications
3537
// applied to the domains, however it does attempt to give a comprehensive
@@ -253,6 +255,12 @@ const ModifierCommand Modifier = ModifierMeta
253255
}
254256
}
255257
}
258+
259+
// add unmarshaler for CookiePartitionKey type
260+
if t.Name == "CookiePartitionKey" {
261+
t.Extra += gotpl.ExtraCookiePartitionKeyUnmarshaler(snaker.ForceCamelIdentifier(t.Name))
262+
t.SwapEasyJSONUnmarshaler = true
263+
}
256264
}
257265

258266
case "Page":

gen/gotpl/extra.qtpl

+29
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,35 @@ func (t *{%s= typ %}) UnmarshalJSON(buf []byte) error {
354354
}
355355
{% endfunc %}
356356

357+
358+
// ExtraCookiePartitionKeyUnmarshaler is a template that handles unmarshaling
359+
// Network.CookiePartitionKey.
360+
{% func ExtraCookiePartitionKeyUnmarshaler(typ string) %}
361+
// UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
362+
func (t *{%s= typ %}) UnmarshalEasyJSONZZ(in *jlexer.Lexer) {
363+
buf := in.Raw()
364+
if l := len(buf); l > 2 && buf[0] == '"' && buf[l-1] == '"' {
365+
var err error
366+
if t.TopLevelSite, err = strconv.Unquote(string(buf)); err != nil {
367+
in.AddError(err)
368+
}
369+
return
370+
}
371+
dec := json.NewDecoder(bytes.NewReader(buf))
372+
dec.DisallowUnknownFields()
373+
var v struct{
374+
TopLevelSite string `json:"topLevelSite"`
375+
HasCrossSiteAncestor bool `json:"hasCrossSiteAncestor"`
376+
}
377+
if err := dec.Decode(&v); err != nil {
378+
in.AddError(err)
379+
} else {
380+
t.TopLevelSite, t.HasCrossSiteAncestor = v.TopLevelSite, v.HasCrossSiteAncestor
381+
}
382+
}
383+
{% endfunc %}
384+
385+
357386
// ExtraExecutorTemplate is the additional shared executor interface for all
358387
// the domains.
359388
{% func ExtraExecutorTemplate() %}

0 commit comments

Comments
 (0)