Repository: webpack-contrib/css-loader (js)

Issue:
Fix url filter behavior
Related to: https://github.com/webpack-contrib/css-loader/issues/779

The result of the function should be inverted to keep in mind the same behavior when it is a boolean..
I mean when the function return false should not look the ``url``.
This is my configuration in the end:
```javascript
    {
      test: /\.scss$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: [
          {
            loader: 'css-loader',
            options: {
              url: (url, resourcePath) => /\+\+resource\+\+/.test(url)
            }
          },
          'postcss-loader',
          'sass-loader'
        ]
      }),
    },
```

Pull request description:
fix: invert `Function` behavior for `url` and `import` options
<!--
  HOLY CRAP a Pull Request. We ❤️ those!

  If you remove or skip this template, you'll make the 🐼 sad and the mighty god
  of Github will appear and pile-drive the close button from a great height
  while making animal noises.

  Please place an x (no spaces!) in all [ ] that apply
-->

This PR contains a:

- [x] **bugfix**
- [ ] new **feature**
- [ ] **code refactor**
- [x] **test update** <!-- if bug or feature is checked, this should be too -->
- [ ] **typo fix**
- [ ] **metadata update**

### Motivation / Use-Case

fixes #891

### Breaking Changes

Yes

BREAKING CHANGE: you should return `true` when you want handle `url`/`@import` and return `false` if not


### Additional Info

No

Patch:
diff --git a/README.md b/README.md
index efd6bb5..5c67b34 100644
--- a/README.md
+++ b/README.md
@@ -183,9 +183,13 @@ module.exports = {
         options: {
           url: (url, resourcePath) => {
             // resourcePath - path to css file
+            
+            // Don't handle `img.png` urls
+            if (url.includes('img.png')) {
+              return false;
+            }
 
-            // `url()` with `img.png` stay untouched
-            return url.includes('img.png');
+            return true;
           },
         },
       },
@@ -262,8 +266,12 @@ module.exports = {
             // parsedImport.media - media query of `@import`
             // resourcePath - path to css file
 
-            // `@import` with `style.css` stay untouched
-            return parsedImport.url.includes('style.css');
+            // Don't handle `style.css` import
+            if (parsedImport.url.includes('style.css')) {
+              return false;
+            }
+
+            return true;
           },
         },
       },
diff --git a/src/utils.js b/src/utils.js
index 5d8c2d2..d115ce8 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -100,13 +100,13 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
 }
 
 function getFilter(filter, resourcePath, defaultFilter = null) {
-  return (content) => {
-    if (defaultFilter && !defaultFilter(content)) {
+  return (item) => {
+    if (defaultFilter && !defaultFilter(item)) {
       return false;
     }
 
     if (typeof filter === 'function') {
-      return !filter(content, resourcePath);
+      return filter(item, resourcePath);
     }
 
     return true;


Test patch:
diff --git a/test/import-option.test.js b/test/import-option.test.js
index fc6f92d..0cc4590 100644
--- a/test/import-option.test.js
+++ b/test/import-option.test.js
@@ -62,7 +62,12 @@ describe('import option', () => {
           import: (parsedImport, resourcePath) => {
             expect(typeof resourcePath === 'string').toBe(true);
 
-            return parsedImport.url.includes('test.css');
+            // Don't handle `test.css`
+            if (parsedImport.url.includes('test.css')) {
+              return false;
+            }
+
+            return true;
           },
         },
       },
diff --git a/test/url-option.test.js b/test/url-option.test.js
index 42c1a93..a04faa1 100644
--- a/test/url-option.test.js
+++ b/test/url-option.test.js
@@ -62,7 +62,12 @@ describe('url option', () => {
           url: (url, resourcePath) => {
             expect(typeof resourcePath === 'string').toBe(true);
 
-            return url.includes('img.png');
+            // Don't handle `img.png`
+            if (url.includes('img.png')) {
+              return false;
+            }
+
+            return true;
           },
         },
       },