Skip to content

Commit

Permalink
fix: do not consume number token if expression ends with '.'
Browse files Browse the repository at this point in the history
Fix #132

`\b` also matches '.' so the regex for the number expression would match
`41` in `41.7rpx`. Then `UNKNOWN_DIMENSION` would match `.7rpx`
and create the invalid sequence `NumberExpression`, `UnknownDimension`.
  • Loading branch information
ludofischer committed Jan 12, 2022
1 parent 1f2513d commit dfca7c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,15 @@ test(
testValue('calc(1px + 2unknown)', 'calc(1px + 2unknown)')
);

test('decimal unknown units', async () => {
const result = await postcss(reduceCalc()).process(
'p{width: calc(120rpx - 41.7rpx)}',
postcssOpts
);
const warnings = result.warnings();
assert.is(warnings.length, 0);
});

test(
'error with parsing',
testThrows(
Expand Down
2 changes: 1 addition & 1 deletion src/parser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dpcm\b return 'RES';
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dppx\b return 'RES';
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)\% return 'PERCENTAGE';
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)\b return 'NUMBER';
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)(?!".")\b return 'NUMBER';

(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)-?([a-zA-Z_]|[\240-\377]|(\\[0-9a-fA-F]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-fA-F]))([a-zA-Z0-9_-]|[\240-\377]|(\\[0-9a-fA-F]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-fA-F]))*\b return 'UNKNOWN_DIMENSION';

Expand Down

0 comments on commit dfca7c5

Please sign in to comment.