-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Strange behavior of "greedy" option #1039
Comments
zeitgeist87
added a commit
that referenced
this issue
Oct 24, 2016
This bug occurs in the relatively rare case of a pattern matching the empty string. It was reported in issue #1039. If for example a HTML page contains an empty script tag `<script></script>` then the script pattern will match anything inside, which is the empty string. This empty string is then passed to the constructor of the Token class. Since `""` is falsy in Javascript the property `matchedStr` is set to `null`. But the property `matchedStr` is needed to calculate the current position for the greedy feature. A `null` value in `matchedStr` results in a `pos` that is `NaN`. This causes the bug described in issue #1039. Since the property `matchedStr` is only ever needed to calculate the length of the Token, it is more efficient to store the length directly instead of the string. As a side effect this also fixes issue #1039.
This was indeed a bug. It should be fixed now. Thanks for reporting it! |
Thanks! It seems to be fixed now. I'll test my language definition more and then submit it to Prism. |
Since this issue is fixed, I'm closing it. Thanks for your help. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First, I must admit that I have little experience in JavaScript. But I like Prism and now I'm working on a language definition for Django/Jinja2 template languages. Those are 2 popular template languages in Python world with similar syntax, so I'm making one definition for both. You can see my working code here.
I'd say that it works OK in 95% cases and now I try to improve handling of borderline cases. One approach that I've tried is using the
greedy
options for matching template tags{{ ... }}
and{% ... %}
. Indeed, it improved matching, but on some testing samples a strange bug happens: the first string is copy-pasted all over the code snippet.Here's my testing code snippet:
(GitHub has some support for Django/Jinja2 too, BTW)
And here's what I get with my language definition:
As you can see, it works OK except for the "difficult case". Now here's what I get with
greedy
option:As you can see, the "difficult case" is now painted correctly, but the first string
{% load i18n %}
is copy-pasted all over the place.By elimination I found out that "the problem string" with
<script>
tag is causing all this. If I remove it, the copy-pasting problem disappears.I'd like to know: am I doing something wrong or this is a bug in Prism?
The text was updated successfully, but these errors were encountered: