Skip to content

Commit

Permalink
Fix function-url-quotes false positives for SCSS variable and @ c…
Browse files Browse the repository at this point in the history
…haracter (#7416)
  • Loading branch information
mattxwang committed Dec 24, 2023
1 parent e222352 commit cb509a0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-crabs-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `function-url-quotes` false positives for SCSS variable and `@` character
4 changes: 4 additions & 0 deletions lib/rules/function-url-quotes/__tests__/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -764,5 +764,9 @@ testRule({
)`,
description: 'SCSS with',
},
{
code: "a { background: url($asset-prefix + 'assets/images/fa_calculator_blue@2x.png') }",
description: '@ character within URL and string concatenation (#7404)',
},
],
});
14 changes: 7 additions & 7 deletions lib/utils/__tests__/isStandardSyntaxUrl.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ describe('isStandardSyntaxUrl', () => {
it('url with ampersand at the end and double quotes', () => {
expect(isStandardSyntaxUrl('"some/@url"')).toBeTruthy();
});
it('url with ampersand at the start', () => {
it('url with at sign at the start', () => {
expect(isStandardSyntaxUrl('@url/path')).toBeTruthy();
});
it('url with ampersand in the middle', () => {
it('url with at sign in the middle', () => {
expect(isStandardSyntaxUrl('some/@url/path')).toBeTruthy();
});
it('url with ampersand at the end', () => {
it('url with at sign at the end', () => {
expect(isStandardSyntaxUrl('some/@url')).toBeTruthy();
});
it('url with less interpolation without quotes', () => {
Expand Down Expand Up @@ -137,18 +137,18 @@ describe('isStandardSyntaxUrl', () => {
it('sass variable concat with single quotes string', () => {
expect(isStandardSyntaxUrl("$sass-variable + 'foo'")).toBeFalsy();
});
it('sass variable concat with escaped single quotes string', () => {
expect(isStandardSyntaxUrl("$sass-variable + 'foo'")).toBeFalsy();
});
it('sass variable concat with double quotes string', () => {
expect(isStandardSyntaxUrl("$sass-variable + 'foo'")).toBeFalsy();
expect(isStandardSyntaxUrl('$sass-variable + "foo"')).toBeFalsy();
});
it('sass variable concat with single quotes string without spaces', () => {
expect(isStandardSyntaxUrl("$sass-variable+'foo'")).toBeFalsy();
});
it('sass variable and concatenation', () => {
expect(isStandardSyntaxUrl('$sass-variable + foo')).toBeFalsy();
});
it('sass variable, concatenation, and a quoted at sign', () => {
expect(isStandardSyntaxUrl("$sass-variable + 'foo@bar'")).toBeFalsy();
});
it('sass variable and double concatenation', () => {
expect(isStandardSyntaxUrl('test + $sass-variable + foo')).toBeFalsy();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isStandardSyntaxUrl.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const hasScssInterpolation = require('./hasScssInterpolation.cjs');
const hasTplInterpolation = require('./hasTplInterpolation.cjs');

const IS_LESS_VARIABLE_IN_URL = /^@@?[\w-]+$/;
const IS_SCSS_VARIABLE_IN_URL = /^[$\s\w+\-,./*'"]+$/;
const IS_SCSS_VARIABLE_IN_URL = /^[$\s\w+\-,./*'"@]+$/;

/**
* Check whether a URL is standard
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/isStandardSyntaxUrl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import hasScssInterpolation from './hasScssInterpolation.mjs';
import hasTplInterpolation from './hasTplInterpolation.mjs';

const IS_LESS_VARIABLE_IN_URL = /^@@?[\w-]+$/;
const IS_SCSS_VARIABLE_IN_URL = /^[$\s\w+\-,./*'"]+$/;
const IS_SCSS_VARIABLE_IN_URL = /^[$\s\w+\-,./*'"@]+$/;

/**
* Check whether a URL is standard
Expand Down

0 comments on commit cb509a0

Please sign in to comment.