-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(java) Scientific notation numbers are only legal for floating points #2508
Comments
You want to make an attempt at a patch? Fixing this will likely require splitting the huge regex we currently have up into variants to match the different types... |
I tried the following code locally but it doesn't work. var JAVA_NUMBER_RE = '\\b' +
'(' +
'(' +
'0[bB]([01]+[01_]+[01]+|[01]+)' + // 0b...
'|' +
'0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)' + // 0x...
'|' +
'(' +
'([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?' +
'|' +
'\\.([\\d]+[\\d_]+[\\d]+|[\\d]+)' +
')' +
')' +
'[lLfF]?' + '|' + '(' +
'([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?' +
'|' +
'\\.([\\d]+[\\d_]+[\\d]+|[\\d]+)' +
')' +
'([eE][-+]?\\d+)?' + '[fF]?' + ')'; Regexes are really hard. :D Sorry for bad indentation :( |
Yeah I wouldn't accept that anyways, we need to switch to variants. Look at how some of the other syntaxes use variant for numbers. :-) And we'll need some markup tests for as many number combos as you want to come up with. It's possible we already have some. |
There are some nice apps that can make testing them easier... on Mac: Patterns, Expressions, etc |
Yeah ok, I will try again with variants :-) For sure. I used https://regex101.com/ to test manually the regex with some cases |
It should be easier when you only have to get one type working at a time vs a huge regex for them all, etc... |
btw shouldn't it be the same like hljs.C_NUMBER_RE ? |
That might work for some of the variants... See arcade for an example:
|
We already have tests so you'd just be exepanding those: |
I will try it, it's similar to javascript. |
It's almost hard, because of some other facts: 0779 is a valid octal number |
It is? How so? |
Also, we don't necessarily have to NOT highlight invalid combos as long as we highlight valid ones well. If technically the regex matches "too much" but those things aren't likely to come up in programs then it really doesn't matter. I meant to ask what led to you reporting this bug in the first place? |
Oh no, copy paste error. 0779 is invalid, 077 is valid.
Maybe you are right, highlightJS is not a compiler, it's only a code highlighter. Maybe this was the wrong attempt. |
I'd think octal is pretty easy: it's just a leading 0 followed by 0-7, no? |
|
Looks like a start... add some more tests, get something that passes and I'll review it. Worry about them each one at a time... octal shouldn't worry if others will match... all we care about is if it's a number or not... we don't really care WHICH rule matches it. |
Please add these test cases also then. |
Describe the issue
HighlightJS highlights illegal number literals
Which language seems to have the issue?
java
Are you using
highlight
orhighlightAuto
?highlight
Sample Code to Reproduce
Case a and b should be illegal, case c and d are fine.
https://jsfiddle.net/e1xnqskb/
Expected behavior
I would expect that illegal number literals are not highlighted
Additional context
It's a similar issue to #2507
The text was updated successfully, but these errors were encountered: