Skip to content
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

fix: freeze built-in modes to prevent grammars altering them #2271

Merged
merged 5 commits into from Nov 20, 2019

Conversation

joshgoebel
Copy link
Member

No description provided.

- previously a ill-behaved grammar could change the global modes
- this prevents that behavior
@joshgoebel
Copy link
Member Author

joshgoebel commented Nov 12, 2019

@egor-rogov

Technically this would be a breaking change for any BADLY behaved 3rd grammars that were taking advantage of this loophole before... That doesn't really both me a lot (since I'm assuming it's a small number or maybe zero). I'm also not convinced we need a MAJOR release for this.

If you don't think we can accept this kind of potential breakage in a minor release then I suppose my preference would be to isolate the compile steps so that we just refuse to compile poor grammars and keep working with the good grammars. (although that's also a -slightly- breaking change, depending on your definition of breaking)

IE, so then if someone used a "broken" grammar it would just highlight as "plaintext" (ie, no highlighting) with the next version, and they would have to fix their broken grammar. This was on my list of things to do eventually, but wasn't planning on getting to it until later.

Thoughts?

@joshgoebel joshgoebel added this to the 9.17 milestone Nov 12, 2019
@joshgoebel joshgoebel added this to In Progress in Highlight.js via automation Nov 12, 2019
Copy link
Collaborator

@egor-rogov egor-rogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@egor-rogov
Copy link
Collaborator

Technically this would be a breaking change for any BADLY behaved 3rd grammars that were taking advantage of this loophole before... That doesn't really both me a lot (since I'm assuming it's a small number or maybe zero). I'm also not convinced we need a MAJOR release for this.

Well, let's keep the breaking changes (potential or not) for major releases.

If you don't think we can accept this kind of potential breakage in a minor release then I suppose my preference would be to isolate the compile steps so that we just refuse to compile poor grammars and keep working with the good grammars. (although that's also a -slightly- breaking change, depending on your definition of breaking)

Are we in a hurry? Why not just wait for some time with this PR until the next major release?

@joshgoebel
Copy link
Member Author

joshgoebel commented Nov 14, 2019

Are we in a hurry? Why not just wait for some time with this PR until the next major release?

Well, I tend to have had poor experiences with long-lived PRs in general. There are git strategies to make dealing with such things easier, but still I've always found it's best to get things finished up and committed, when possible.

Also, technically right now any language grammar loaded can break ALL the other grammars by subverting the constant utility rules (either on purpose or on accident). Seems kind of bad.

How do you feel about my suggestion if I just go ahead and add a catch so that any 3rd party languages behaving poorly get "disabled" (with a console error) but all other languages continue working just fine? Would that be a let us get this merged now vs later?

IE, I'd just place a try/catch in registerLanguage that catches TypeError and then say registers an empty plaint/text grammar instead...

@egor-rogov
Copy link
Collaborator

How do you feel about my suggestion if I just go ahead and add a catch so that any 3rd party languages behaving poorly get "disabled" (with a console error) but all other languages continue working just fine?

I think it returns us back to #2276, because you don't want an error to get swallowed when developing new grammar.

As I can see in #2273, there are quite a few breaking changes for v10. Maybe these changes worth a separate branch?

@joshgoebel
Copy link
Member Author

joshgoebel commented Nov 14, 2019

I think it returns us back to #2276, because you don't want an error to get swallowed when developing new grammar.

Yes, I'm fine with making that a requirement here. But if we make that a thing, do you think this is safe to go in and the default "production" mode would then be that broken languages (which there might not even be any!) are just disabled, while other grammars continue to work just time.

As I can see in #2273, there are quite a few breaking changes for v10. Maybe these changes worth a separate branch?

After 9.17 I'll probably make a 9_STABLE branch or similar and then master will become the 10 branch. I was just writing down the list in an issue so I don't forget things. :)

@egor-rogov
Copy link
Collaborator

Yes, I'm fine with making that a requirement here. But if we make that a thing, do you think this is safe to go in and the default "production" mode would then be that broken languages (which there might not even be any!) are just disabled, while other grammars continue to work just time.

I think it's OK in this case.

@joshgoebel
Copy link
Member Author

@egor-rogov Merging this now that #2286 has hit.

@egor-rogov
Copy link
Collaborator

@egor-rogov Merging this now that #2286 has hit.

Yep.

@joshgoebel joshgoebel merged commit fa62c84 into master Nov 20, 2019
Highlight.js automation moved this from In Progress to Done Nov 20, 2019
@joshgoebel joshgoebel deleted the freeze_built_in_constant_modes branch December 6, 2019 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Highlight.js
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants