@@ -49,6 +49,7 @@ import {
4949 evalHeadProps ,
5050 evalHeadValue ,
5151 resourceIdentity ,
52+ asciiLowerCase ,
5253 replaceableIdentity ,
5354 resolveHead ,
5455 STYLESHEET_FETCH_META
@@ -341,7 +342,9 @@ function joinAssetPath(base, file) {
341342// commas TRAILING that run separate it from the next candidate. Commas INSIDE a
342343// URL (`/w,400/hero.avif`, the shape image CDNs emit) are part of it, so they no
343344// longer read as two relative candidates.
344- function eachCandidateUrl ( srcset , visit ) {
345+ // `visit(url, descriptors)` sees each candidate's URL and the descriptor text
346+ // between it and the closing comma, so a descriptor check never scans a URL.
347+ function eachCandidate ( srcset , visit ) {
345348 let i = 0 ;
346349 const n = srcset . length ;
347350 while ( i < n ) {
@@ -351,12 +354,15 @@ function eachCandidateUrl(srcset, visit) {
351354 if ( i === start ) return false ;
352355 const raw = srcset . slice ( start , i ) ;
353356 const url = raw . replace ( / , + $ / , "" ) ;
354- if ( url && visit ( url ) ) return true ;
357+ let descriptors = "" ;
355358 // A URL that did not end in commas is followed by its descriptor; the
356359 // comma that closes this candidate comes after it.
357360 if ( url === raw ) {
361+ const from = i ;
358362 while ( i < n && srcset [ i ] !== "," ) i ++ ;
363+ descriptors = srcset . slice ( from , i ) ;
359364 }
365+ if ( url && visit ( url , descriptors ) ) return true ;
360366 }
361367 return false ;
362368}
@@ -366,14 +372,17 @@ function eachCandidateUrl(srcset, visit) {
366372// places on any route below the root — which is true whether or not `_base` is
367373// set, hence no base guard here.
368374function hasRelativeCandidate ( srcset ) {
369- return eachCandidateUrl ( srcset , url => ! / ^ (?: [ a - z A - Z ] [ a - z A - Z 0 - 9 + . - ] * : | \/ ) / . test ( url ) ) ;
375+ return eachCandidate ( srcset , url => ! / ^ (?: [ a - z A - Z ] [ a - z A - Z 0 - 9 + . - ] * : | \/ ) / . test ( url ) ) ;
370376}
371377
372378// Whether any candidate carries a width descriptor (`400w`), which the spec
373- // makes `imagesizes` mandatory for. Descriptors sit between a candidate's URL
374- // and the comma that closes it, so a separator always precedes them.
379+ // makes `imagesizes` mandatory for. Only descriptor text is examined: a URL is
380+ // free-form and `https://cdn.example/image,400w 1x` is one density candidate,
381+ // not a width descriptor.
375382function hasWidthDescriptor ( srcset ) {
376- return / [ \s , ] \d + (?: \. \d + ) ? w (? = [ \s , ] | $ ) / . test ( srcset ) ;
383+ return eachCandidate ( srcset , ( _ , descriptors ) =>
384+ / (?: ^ | \s ) \d + (?: \. \d + ) ? w (? = \s | $ ) / . test ( descriptors )
385+ ) ;
377386}
378387
379388function resolveAssets ( moduleUrl , manifest ) {
@@ -1243,12 +1252,6 @@ export function styleNonce(nonce) {
12431252 return destinationNonce ( nonce , "style" ) ;
12441253}
12451254
1246- // HTML compares rel/as ASCII case-insensitively; toLowerCase would fold a
1247- // non-ASCII character onto an ASCII one the parser never matches.
1248- function asciiLowerCase ( value ) {
1249- return value . replace ( / [ A - Z ] / g, c => String . fromCharCode ( c . charCodeAt ( 0 ) + 32 ) ) ;
1250- }
1251-
12521255// Attribute names are ASCII case-insensitive, so a caller-supplied `Nonce`
12531256// counts as one too.
12541257function hasNonceProp ( props ) {
0 commit comments