Skip to content

Commit 5e0eb33

Browse files
committed
Parser: fix is_num() and is_ident() checks to use the current codepoint as the first character. Fixes #204.
1 parent 42f1745 commit 5e0eb33

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

docs/resources.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ In other languages:
5555

5656
### Books
5757

58-
- [Fairchild, Mark D.](http://markfairchild.org/)_Color Appearance Models_, 3rd Edition, Wiley-IS&T, Chichester, UK (2013); ISBN 978-1-119-96703-3
59-
- [Poynton, Charles](http://poynton.ca/)_Digital Video and HD Algorithms and Interfaces_, Second edition (Burlington, Mass.: Morgan Kaufmann/Elsevier, 2012)
58+
- [Fairchild, Mark D.](http://markfairchild.org/)[_Color Appearance Models_](https://www.wiley.com/en-us/Color+Appearance+Models%2C+3rd+Edition-p-9781119967033), 3rd Edition, Wiley, 2013.
59+
- Morovič, Ján — [_Color Gamut Mapping_](https://www.wiley.com/en-ie/Color+Gamut+Mapping-p-9780470030325), Wiley, 2008.
60+
- [Poynton, Charles](http://poynton.ca/)[_Digital Video and HD Algorithms and Interfaces_](https://www.elsevier.com/books/digital-video-and-hd/poynton/978-0-12-391926-7), 2nd Edition, Morgan Kaufmann, 2012.

src/parse.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -176,30 +176,30 @@ export function tokenize(str = '') {
176176
}
177177

178178
if (ch === '+') {
179+
_i--;
179180
if (is_num(chars)) {
180-
_i--;
181181
tokens.push(num(chars));
182182
continue;
183183
}
184184
return undefined;
185185
}
186186

187187
if (ch === '-') {
188+
_i--;
188189
if (is_num(chars)) {
189-
_i--;
190190
tokens.push(num(chars));
191191
continue;
192-
} else if (is_ident(chars)) {
193-
_i--;
192+
}
193+
if (is_ident(chars)) {
194194
tokens.push({ type: Tok.Ident, value: ident(chars) });
195195
continue;
196196
}
197197
return undefined;
198198
}
199199

200200
if (ch === '.') {
201+
_i--;
201202
if (is_num(chars)) {
202-
_i--;
203203
tokens.push(num(chars));
204204
continue;
205205
}

test/parse.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,8 @@ tape('undefined', function (test) {
300300
test.equal(parse(undefined), undefined);
301301
test.end();
302302
});
303+
304+
tape('Issue #204', function (test) {
305+
test.equal(parse('oklch(70% 0..1 156)'), undefined);
306+
test.end();
307+
});

0 commit comments

Comments
 (0)