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

use null prototype objects for languages/aliases #2636

Merged
merged 3 commits into from Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -8,10 +8,12 @@ Language Improvements:

- enh(matlab) Add new R2019b `arguments` keyword and fix `enumeration` keyword (#2619) [Andrew Janke][]
- fix(kotlin) Remove very old keywords and update example code (#2623) [kageru][]
- fix(night) Prevent object prototypes method values from being returned in `getLanguage` (#2636) [night][]

[Andrew Janke]: https://github.com/apjanke
[Samia Ali]: https://github.com/samiaab1990
[kageru]: https://github.com/kageru
[night]: https://github.com/night


## Version 10.1.1
Expand Down
4 changes: 2 additions & 2 deletions src/highlight.js
Expand Up @@ -29,9 +29,9 @@ const HLJS = function(hljs) {

// Global internal variables used within the highlight.js library.
/** @type {Record<string, Language>} */
var languages = {};
var languages = Object.create(null);
/** @type {Record<string, string>} */
var aliases = {};
var aliases = Object.create(null);
/** @type {HLJSPlugin[]} */
var plugins = [];

Expand Down
12 changes: 12 additions & 0 deletions test/api/getLanguage.js
Expand Up @@ -41,4 +41,16 @@ describe('.getLanguage()', () => {
result.should.have.property('aliases').with.containEql('cs');
should.strictEqual(result, hljs.getLanguage('csharp'))
});

it('should not succeed for constructor', () => {
const result = hljs.getLanguage('constructor');

should.strictEqual(result, undefined);
});

it('should not succeed for __proto__', () => {
const result = hljs.getLanguage('__proto__');

should.strictEqual(result, undefined);
});
});