postcss / postcss-url

PostCSS plugin to rebase url(), inline or copy asset.
MIT License
377 stars 59 forks source link

Processing fails if content of url() cannot be parsed as path #89

Closed varyen closed 7 years ago

varyen commented 7 years ago

Hi! I have following code for my css:

.techsupport svg rect {
    fill: url(#some-id");
}

AND inline svg on my page:

<a href="/support/" class="techsupport">
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <defs>
            <linearGradient id="some-id" x1="100%" y1="100%" x2="0%" y2="0%">
                <stop offset="0%"/>
                <stop offset="100%"/>
            </linearGradient>
            <mask id="svgm">
                <image width="100%" height="100%" xlink:href="/assets/img/icons/support.png"></image>
            </mask>
        </defs>
        <rect mask="url(#svgm)" x="0" y="0" width="100%" height="100%"></rect>
    </svg>
</a>

I'm using it to dynamicly change linearGradient stop { stop-color: } on hover. And I'm using postcss-url with my own defined function to rewrite my image urls.

So, the problem is postcss-url fails when it tries to parse fill: url(#some-id"); because obliviously it's not a path.

events.js:160
      throw er; // Unhandled 'error' event
      ^
TypeError: Path must be a string. Received null
    at assertPath (path.js:7:11)
    at Object.join (path.js:468:7)
    at prepareAsset (C:\WebDev\home\project.local\www\node_modules\postcss-url\src\lib\paths.js:92:31)
    at replaceUrl (C:\WebDev\home\project.local\www\node_modules\postcss-url\src\index.js:64:19)
    at decl.value.decl.value.replace (C:\WebDev\home\project.local\www\node_modules\postcss-url\src\index.js:94:28)
    at RegExp.[Symbol.replace] (native)
    at RegExp.[Symbol.replace] (native)
    at String.replace (native)
    at declProcessor (C:\WebDev\home\project.local\www\node_modules\postcss-url\src\index.js:93:10)
    at styles.walkDecls (C:\WebDev\home\project.local\www\node_modules\postcss-url\src\index.js:115:20)

Also it's hard to debug because there's no info on parsed file and line with this "error". Checked it on 6.0.2.

sergcen commented 7 years ago

@varyen, i get it, try to fix it soon

sergcen commented 7 years ago

use 6.0.1 before i fix it

sergcen commented 7 years ago

fixed in 6.0.3 can you check?

varyen commented 7 years ago

Works as intended, thank you :)