Skip to content

Commit f1d819c

Browse files
authored
Merge pull request #481 from ampproject/master
Snapshot release v5
2 parents ca6f35a + f7c12ca commit f1d819c

File tree

321 files changed

+52658
-22898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

321 files changed

+52658
-22898
lines changed

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ require (
77
github.com/ampproject/amphtml v0.0.0-20180912232012-d3df64d07ae9
88
github.com/go-acme/lego/v3 v3.2.0
99
github.com/gofrs/flock v0.7.1
10-
github.com/golang/protobuf v1.3.2
11-
github.com/google/go-cmp v0.3.0
10+
github.com/golang/protobuf v1.4.1
11+
github.com/google/go-cmp v0.5.0
12+
github.com/kylelemons/godebug v1.1.0
1213
github.com/pelletier/go-toml v1.1.0
1314
github.com/pkg/errors v0.8.1
1415
github.com/pquerna/cachecontrol v0.0.0-20180306154005-525d0eb5f91d
1516
github.com/prometheus/client_golang v1.1.0
1617
github.com/stretchr/testify v1.4.0
1718
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
1819
golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3
19-
google.golang.org/grpc v1.20.1
20+
google.golang.org/grpc v1.27.0
21+
google.golang.org/protobuf v1.25.0
2022
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
2123
gopkg.in/square/go-jose.v2 v2.3.1
2224
)

go.sum

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3
5757
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
5858
github.com/census-instrumentation/opencensus-proto v0.2.0 h1:LzQXZOgg4CQfE6bFvXGM30YZL1WW/M337pXml+GrcZ4=
5959
github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
60+
github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=
61+
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
6062
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
6163
github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4=
6264
github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY=
@@ -78,6 +80,8 @@ github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c
7880
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
7981
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
8082
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
83+
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
84+
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
8185
github.com/exoscale/egoscale v0.18.1 h1:1FNZVk8jHUx0AvWhOZxLEDNlacTU0chMXUUNkm9EZaI=
8286
github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE=
8387
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
@@ -111,12 +115,23 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
111115
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
112116
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
113117
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
118+
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
119+
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
120+
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
121+
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
122+
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
123+
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
124+
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
114125
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
115126
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
116127
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
117128
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
118129
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
119130
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
131+
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
132+
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
133+
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
134+
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
120135
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
121136
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
122137
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -169,6 +184,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
169184
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
170185
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
171186
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
187+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
188+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
172189
github.com/labbsr0x/bindman-dns-webhook v1.0.2 h1:I7ITbmQPAVwrDdhd6dHKi+MYJTJqPCK0jE6YNBAevnk=
173190
github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA=
174191
github.com/labbsr0x/goh v1.0.1 h1:97aBJkDjpyBZGPbQuOK5/gHcSFbcr5aRsq3RSRJFpPk=
@@ -240,6 +257,8 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:
240257
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
241258
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE=
242259
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
260+
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=
261+
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
243262
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
244263
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
245264
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
@@ -341,6 +360,9 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
341360
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
342361
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
343362
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
363+
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
364+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
365+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
344366
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
345367
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
346368
google.golang.org/api v0.8.0 h1:VGGbLNyPF7dvYHhcUGYBBGCRDDK0RRJAI6KCvo0CL+E=
@@ -354,11 +376,26 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRn
354376
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
355377
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 h1:nfPFGzJkUDX6uBmpN/pSw7MbOAWegH5QDQuoXFHedLg=
356378
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
379+
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
380+
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
381+
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
357382
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
358383
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
359384
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
360385
google.golang.org/grpc v1.20.1 h1:Hz2g2wirWK7H0qIIhGIqRGTuMwTE8HEKFnDZZ7lm9NU=
361386
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
387+
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
388+
google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=
389+
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
390+
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
391+
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
392+
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
393+
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
394+
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
395+
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
396+
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
397+
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
398+
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
362399
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
363400
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
364401
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -387,3 +424,4 @@ honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWh
387424
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
388425
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
389426
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
427+
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

packager/signer/signer.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,26 @@ func formatLinkHeader(preloads []*rpb.Metadata_Preload) (string, error) {
447447
return "", errors.Errorf("Missing `as` attribute for preload URL: %q\n", preload.Url)
448448
}
449449

450+
valid := true
450451
var value strings.Builder
451452
value.WriteByte('<')
452453
value.WriteString(u.String())
453454
value.WriteString(">;rel=preload;as=")
454455
value.WriteString(preload.As)
455-
values = append(values, value.String())
456+
for _, attr := range preload.GetAttributes() {
457+
value.WriteByte(';')
458+
value.WriteString(attr.Key)
459+
value.WriteByte('=')
460+
quotedVal, err := util.QuotedString(attr.Val)
461+
if err != nil {
462+
valid = false
463+
break
464+
}
465+
value.WriteString(quotedVal)
466+
}
467+
if valid {
468+
values = append(values, value.String())
469+
}
456470
}
457471
return strings.Join(values, ","), nil
458472
}

packager/signer/signer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ func (this *SignerSuite) TestAddsLinkHeaders() {
479479
Sign: &util.URLPattern{[]string{"https"}, "", this.httpsHost(), stringPtr("/amp/.*"), []string{}, stringPtr(""), false, 2000, nil}}}
480480
this.fakeHandler = func(resp http.ResponseWriter, req *http.Request) {
481481
resp.Header().Set("Content-Type", "text/html; charset=utf-8")
482-
resp.Write([]byte("<html amp><head><link rel=stylesheet href=foo><script src=bar>"))
482+
resp.Write([]byte(`<html amp><head><link rel=stylesheet href=foo><script src=bar></script><link rel=preload as=image href=baz imagesizes="100vw" imagesrcset="qux">`))
483483
}
484484
target := "/priv/doc?sign=" + url.QueryEscape(this.httpsURL()+fakePath)
485485
resp := pkgt.NewRequest(this.T(), this.new(urlSets), target).SetHeaders("", header).Do()
486486
this.Assert().Equal(http.StatusOK, resp.StatusCode, "incorrect status: %#v", resp)
487487

488488
exchange, err := signedexchange.ReadExchange(resp.Body)
489489
this.Require().NoError(err)
490-
this.Assert().Equal("<foo>;rel=preload;as=style,<bar>;rel=preload;as=script", exchange.ResponseHeaders.Get("Link"))
490+
this.Assert().Equal("<foo>;rel=preload;as=style,<bar>;rel=preload;as=script,<baz>;rel=preload;as=image;imagesizes=\"100vw\";imagesrcset=\"qux\"", exchange.ResponseHeaders.Get("Link"))
491491
}
492492

493493
func (this *SignerSuite) TestEscapesLinkHeaders() {
@@ -500,15 +500,15 @@ func (this *SignerSuite) TestEscapesLinkHeaders() {
500500
// However, it would be nice to limit the impact that could be
501501
// caused by transformation of an invalid AMP, e.g. on a
502502
// same-origin impression.
503-
resp.Write([]byte(`<html amp><head><script src="https://foo.com/a,b>c?d>e|f">`))
503+
resp.Write([]byte(`<html amp><head><script src="https://foo.com/a,b>c?d>e|f"></script><link rel=preload as=image href=bar imagesrcset='test"ing'>`))
504504
}
505505
target := "/priv/doc?sign=" + url.QueryEscape(this.httpsURL()+fakePath)
506506
resp := pkgt.NewRequest(this.T(), this.new(urlSets), target).SetHeaders("", header).Do()
507507
this.Assert().Equal(http.StatusOK, resp.StatusCode, "incorrect status: %#v", resp)
508508

509509
exchange, err := signedexchange.ReadExchange(resp.Body)
510510
this.Require().NoError(err)
511-
this.Assert().Equal("<https://foo.com/a,b%3Ec?d%3Ee%7Cf>;rel=preload;as=script", exchange.ResponseHeaders.Get("Link"))
511+
this.Assert().Equal("<https://foo.com/a,b%3Ec?d%3Ee%7Cf>;rel=preload;as=script,<bar>;rel=preload;as=image;imagesrcset=\"test\\\"ing\"", exchange.ResponseHeaders.Get("Link"))
512512
}
513513

514514
func (this *SignerSuite) TestRemovesHopByHopHeaders() {

transformer/internal/amphtml/srcset.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,39 @@ func roundUp(w int) int {
7878
// more spaces + a non empty string containing no space or commas).
7979
// Doesn't capture the initial space.
8080
//
81-
// \s* Match, but don't capture leading spaces
81+
// \s* Match, but don't capture leading spaces.
8282
// (?:,\s*)? Optionally match comma and trailing space,
8383
// but don't capture comma.
8484
// ([^,\s]\S*[^,\s]) Match something like "google.com/favicon.ico"
85-
// but not ",google.com/favicon.ico,"
85+
// but not ",google.com/favicon.ico,".
8686
// \s* Match, but don't capture spaces.
87-
// ([\d]+.?[\d]*[w|x])? e.g. "5w" or "5x" or "10.2x"
87+
// ( Match the width or density descriptor...
88+
// [1-9]\d*[wx] which is a non-zero integer followed by a w
89+
// or an x ...
90+
// | or ...
91+
// [1-9]\d*\.\d+x a decimal with its whole-number part greater
92+
// than zero and followed by an x ...
93+
// | or ...
94+
// 0\.\d*[1-9]\d*x a decimal with its fractional part greater
95+
// than zero and followed by an x ...
96+
// )? and make it optional.
8897
// \s* Match, but don't capture space
8998
// (?:(,)\s*)? Optionally match comma and trailing space,
9099
// capturing comma.
91-
var imageCandidateRE = regexp.MustCompile(`\s*(?:,\s*)?([^,\s]\S*[^,\s])\s*([\d]+.?[\d]*[w|x])?\s*(?:(,)\s*)?`)
100+
var imageCandidateRE = regexp.MustCompile(
101+
`\s*` +
102+
`(?:,\s*)?` +
103+
`([^,\s]\S*[^,\s])` +
104+
`\s*` +
105+
`(` +
106+
`[1-9]\d*[wx]` +
107+
`|` +
108+
`[1-9]\d*\.\d+x` +
109+
`|` +
110+
`0\.\d*[1-9]\d*x` +
111+
`)?` +
112+
`\s*` +
113+
`(?:(,)\s*)?`)
92114

93115
// ParseSrcset parses the given srcset attribute value of its
94116
// image candidates (as defined by

transformer/internal/htmlnode/htmlnode.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ func Next(n *html.Node) *html.Node {
5252
return n.FirstChild
5353
}
5454

55+
return NextSkippingChildren(n)
56+
}
57+
58+
// NextSkippingChildren returns the next node in document order, but ignores the children of the passed in node.
59+
// Will iterate upwards until it finds a next node, or hits the root node (which would return nil).
60+
func NextSkippingChildren(n *html.Node) *html.Node {
61+
if n == nil {
62+
return nil
63+
}
64+
5565
c := n.NextSibling
5666
p := n.Parent
5767
for c == nil && p != nil {

transformer/internal/htmlnode/htmlnode_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,41 @@ func TestNextAndPrev(t *testing.T) {
209209
}
210210

211211
}
212+
213+
func TestNextSkippingChildren(t *testing.T) {
214+
// This creates a tree of
215+
// root
216+
// |- div
217+
// |- span
218+
// |- i
219+
// |- next
220+
root := html.Node{Data: "root"}
221+
div := html.Node{Data: "div"}
222+
expected := html.Node{Data: "expected"}
223+
span := html.Node{Data: "span"}
224+
i := html.Node{Data: "i"}
225+
root.AppendChild(&div)
226+
root.AppendChild(&expected)
227+
div.AppendChild(&span)
228+
span.AppendChild(&i)
229+
230+
result := NextSkippingChildren(&div)
231+
if result != &expected {
232+
t.Errorf("NextSkippingChildren(div) = %v, want %v", result, expected)
233+
}
234+
235+
result = NextSkippingChildren(&span)
236+
if result != &expected {
237+
t.Errorf("NextSkippingChildren(span) = %v, want %v", result, expected)
238+
}
239+
240+
result = NextSkippingChildren(&i)
241+
if result != &expected {
242+
t.Errorf("NextSkippingChildren(span) = %v, want %v", result, expected)
243+
}
244+
245+
result = NextSkippingChildren(&expected)
246+
if result != nil {
247+
t.Errorf("NextSkippingChildren(span) = %v, want nil", result)
248+
}
249+
}

0 commit comments

Comments
 (0)