Skip to content

Commit 7241013

Browse files
nightjoshgoebel
authored andcommitted
(parser) use null prototype objects for languages/aliases (#2636)
Fix: Discord uses getLanguage to validate that a language specified exists in highlightJS and retrieve metadata about the language for code block highlighting in chat. Because highlightJS returns prototype values instead of the highlight languages themselves, the result is a few different bugs in our clients which expect the return type to be only `Language | undefined`.
1 parent 93fd0d7 commit 7241013

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGES.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## Version 10.1.2
2+
3+
Fixes:
4+
5+
- fix(night) Prevent object prototype values from being returned by `getLanguage` (#2636) [night][]
6+
7+
[night]: https://github.com/night
8+
9+
110
## Version 10.1.1
211

312
Fixes:

src/highlight.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const HLJS = function(hljs) {
2929

3030
// Global internal variables used within the highlight.js library.
3131
/** @type {Record<string, Language>} */
32-
var languages = {};
32+
var languages = Object.create(null);
3333
/** @type {Record<string, string>} */
34-
var aliases = {};
34+
var aliases = Object.create(null);
3535
/** @type {HLJSPlugin[]} */
3636
var plugins = [];
3737

test/api/getLanguage.js

+12
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@ describe('.getLanguage()', () => {
4141
result.should.have.property('aliases').with.containEql('cs');
4242
should.strictEqual(result, hljs.getLanguage('csharp'))
4343
});
44+
45+
it('should not succeed for constructor', () => {
46+
const result = hljs.getLanguage('constructor');
47+
48+
should.strictEqual(result, undefined);
49+
});
50+
51+
it('should not succeed for __proto__', () => {
52+
const result = hljs.getLanguage('__proto__');
53+
54+
should.strictEqual(result, undefined);
55+
});
4456
});

0 commit comments

Comments
 (0)