@@ -122,10 +122,10 @@ protected function combineImports($source, $content, $parents)
122122 # fetch path
123123 (?P<path>
124124
125- # do not fetch data uris or external sources
125+ # do not fetch data uris, external sources or absolute paths
126126 (?!(
127127 [" \']?
128- (data|https?):
128+ (data: |https?: \\ / \\ /| \\ /)
129129 ))
130130
131131 .+?
@@ -166,10 +166,10 @@ protected function combineImports($source, $content, $parents)
166166 # fetch path
167167 (?P<path>
168168
169- # do not fetch data uris or external sources
169+ # do not fetch data uris, external sources or absolute paths
170170 (?!(
171171 [" \']?
172- (data|https?):
172+ (data: |https?: \\ / \\ /| \\ /)
173173 ))
174174
175175 .+?
@@ -380,17 +380,7 @@ protected function move(Converter $converter, $content)
380380 (?P<quotes>[" \'])?
381381
382382 # fetch path
383- (?P<path>
384-
385- # do not fetch data uris or external sources
386- (?!(
387- \s?
388- [" \']?
389- (data|https?):
390- ))
391-
392- .+?
393- )
383+ (?P<path>.+?)
394384
395385 # close path enclosure
396386 (?(quotes)(?P=quotes))
@@ -417,16 +407,7 @@ protected function move(Converter $converter, $content)
417407 (?P<quotes>[" \'])
418408
419409 # fetch path
420- (?P<path>
421-
422- # do not fetch data uris or external sources
423- (?!(
424- [" \']?
425- (data|https?):
426- ))
427-
428- .+?
429- )
410+ (?P<path>.+?)
430411
431412 # close path enclosure
432413 (?P=quotes)
@@ -450,29 +431,30 @@ protected function move(Converter $converter, $content)
450431 // determine if it's a url() or an @import match
451432 $ type = (strpos ($ match [0 ], '@import ' ) === 0 ? 'import ' : 'url ' );
452433
453- // attempting to interpret GET-params makes no sense, so let's discard them for awhile
454- $ params = strrchr ($ match ['path ' ], '? ' );
455- $ url = $ params ? substr ($ match ['path ' ], 0 , -strlen ($ params )) : $ match ['path ' ];
434+ $ url = $ match ['path ' ];
435+ if ($ this ->canImportByPath ($ url )) {
436+ // attempting to interpret GET-params makes no sense, so let's discard them for awhile
437+ $ params = strrchr ($ url , '? ' );
438+ $ url = $ params ? substr ($ url , 0 , -strlen ($ params )) : $ url ;
456439
457- // fix relative url
458- $ url = $ converter ->convert ($ url );
440+ // fix relative url
441+ $ url = $ converter ->convert ($ url );
459442
460- // now that the path has been converted, re-apply GET-params
461- $ url .= $ params ;
443+ // now that the path has been converted, re-apply GET-params
444+ $ url .= $ params ;
445+ }
462446
463447 // build replacement
464448 $ search [] = $ match [0 ];
465- if ($ type == 'url ' ) {
449+ if ($ type === 'url ' ) {
466450 $ replace [] = 'url( ' .$ url .') ' ;
467- } elseif ($ type == 'import ' ) {
451+ } elseif ($ type === 'import ' ) {
468452 $ replace [] = '@import " ' .$ url .'" ' ;
469453 }
470454 }
471455
472456 // replace urls
473- $ content = str_replace ($ search , $ replace , $ content );
474-
475- return $ content ;
457+ return str_replace ($ search , $ replace , $ content );
476458 }
477459
478460 /**
@@ -671,4 +653,16 @@ protected function canImportBySize($path)
671653 {
672654 return ($ size = @filesize ($ path )) && $ size <= $ this ->maxImportSize * 1024 ;
673655 }
656+
657+ /**
658+ * Check if file a file can be imported, going by the path.
659+ *
660+ * @param string $path
661+ *
662+ * @return bool
663+ */
664+ protected function canImportByPath ($ path )
665+ {
666+ return preg_match ('/^(data:|https?:| \\/)/ ' , $ path ) === 0 ;
667+ }
674668}
0 commit comments