Skip to content

Commit

Permalink
Fix toTokenizedValue() execution with URL values (#1066)
Browse files Browse the repository at this point in the history
* changed toTokenizedValue.js

* add tests for issue #986

Co-authored-by: wicaksa <wicaksa_r@yahoo.com>
Co-authored-by: sarahhling <sarahling1103@gmail.com>
Co-authored-by: hnadrian <hngt.adrian@gmail.com>

Co-authored-by: wicaksa <wicaksa_r@yahoo.com>
Co-authored-by: Mingjie Jiang <jiang@mingjie.dev>
Co-authored-by: hnadrian <hngt.adrian@gmail.com>
  • Loading branch information
4 people authored Oct 4, 2022
1 parent 241e87e commit aa59b01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/convert/toTokenizedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const toTokenizedValue = (
/** @type {string} */
scale,
) => value.replace(
/([+-])?((?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)?(\$|--)([$\w-]+)/g,
/([+-])?((?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)?(\$|(?<!url\(.*)--|--(?!.*\)))([$\w-]+)/g,
($0, direction, multiplier, separator, token) => (
separator == "$" == !!multiplier
? $0
Expand Down
33 changes: 33 additions & 0 deletions packages/core/tests/issue-986.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { toTokenizedValue } from '../src/convert/toTokenizedValue.js'

describe('Issue #986', () => {
const sampleURL = 'https://example.com/images/some-url-string-1--Version-6.jpg'

test('url only', () => {
const tokenizedUrlOnly = toTokenizedValue(`url(${sampleURL})`, '', '')
expect(tokenizedUrlOnly).toBe(`url(${sampleURL})`)
})

test('url with additional properties before or after', () => {
const tokenizedConstantSuffix = toTokenizedValue(`url(${sampleURL}) fixed`, '', '')
expect(tokenizedConstantSuffix).toBe(`url(${sampleURL}) fixed`)

const tokenizedConstantPrefix = toTokenizedValue(`repeat url(${sampleURL})`, '', '')
expect(tokenizedConstantPrefix).toBe(`repeat url(${sampleURL})`)

const tokenizedVariableSuffix = toTokenizedValue(`url(${sampleURL}) -1--Version-6`, '', '')
expect(tokenizedVariableSuffix).toBe(`url(${sampleURL}) calc(var(--Version-6)*-1)`)

const tokenizedVariablePrefix = toTokenizedValue(`-1--Version-6 url(${sampleURL})`, '', '')
expect(tokenizedVariablePrefix).toBe(`calc(var(--Version-6)*-1) url(${sampleURL})`)
})

test('url with additional properties both before and after', () => {
const tokenizedConstantPrePostfix = toTokenizedValue(`repeat url(${sampleURL}) fixed`, '', '')
expect(tokenizedConstantPrePostfix).toBe(`repeat url(${sampleURL}) fixed`)

const tokenizedVariablePrePostfix = toTokenizedValue(`-1--Version-6 url(${sampleURL}) -1--Version-7`, '', '')
expect(tokenizedVariablePrePostfix).toBe(`calc(var(--Version-6)*-1) url(${sampleURL}) calc(var(--Version-7)*-1)`)

})
})

0 comments on commit aa59b01

Please sign in to comment.