@@ -10,7 +10,7 @@ module.exports = function () {
1010
1111function transform ( node ) {
1212 const tags = [ 'img' , 'source' ]
13-
13+
1414 if ( tags . indexOf ( node . tag ) !== - 1 && node . attrs ) {
1515 node . attrs . forEach ( attr => {
1616 if ( attr . name === 'srcset' ) {
@@ -22,12 +22,11 @@ function transform (node) {
2222 }
2323
2424 // http://w3c.github.io/html/semantics-embedded-content.html#ref-for-image-candidate-string-5
25-
26- const spaceCharacters = / [ \t \n \f \r ] + /
27- const escapedSpaceCharacters = / ^ ( [ \t \n \f \r ] | \\ t | \\ n | \\ f | \\ r ) * /
25+ const escapedSpaceCharacters = / ( | \\ t | \\ n | \\ f | \\ r ) + / g
2826
2927 const imageCandidates = value . substr ( 1 , value . length - 2 ) . split ( ',' ) . map ( s => {
30- const [ url , descriptor ] = s . replace ( escapedSpaceCharacters , '' ) . split ( spaceCharacters , 2 )
28+ // The attribute value arrives here with all whitespace, except normal spaces, represented by escape sequences
29+ const [ url , descriptor ] = s . replace ( escapedSpaceCharacters , ' ' ) . trim ( ) . split ( ' ' , 2 )
3130 return { require : urlToRequire ( url ) , descriptor : descriptor }
3231 } )
3332
@@ -42,15 +41,14 @@ function transform (node) {
4241 }
4342}
4443
45- function urlToRequire ( url ) {
46- // same logic as in transform-require.js
47- var firstChar = url . charAt ( 0 )
48- if ( firstChar === '.' || firstChar === '~' ) {
49- if ( firstChar === '~' ) {
50- var secondChar = url . charAt ( 1 )
51- url = '"' + url . slice ( secondChar === '/' ? 2 : 1 )
52- }
53- return `require("${ url } ")`
54-
44+ function urlToRequire ( url ) {
45+ // same logic as in transform-require.js
46+ var firstChar = url . charAt ( 0 )
47+ if ( firstChar === '.' || firstChar === '~' ) {
48+ if ( firstChar === '~' ) {
49+ var secondChar = url . charAt ( 1 )
50+ url = '"' + url . slice ( secondChar === '/' ? 2 : 1 )
5551 }
52+ return `require("${ url } ")`
5653 }
54+ }
0 commit comments