Skip to content

Commit 6a725bd

Browse files
authored
Check if value is a string in isSimpleTermDefinitionPrefix
1 parent 3704921 commit 6a725bd

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/ContextParser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Tried mapping ${key} to ${JSON.stringify(keyValue)}`, ERROR_CODES.INVALID_KEYWOR
252252
}
253253

254254
if (!Util.isPotentialKeyword(key) && !Util.isTermProtected(context, key)) {
255-
const value = context[key];
255+
const value: unknown = context[key];
256256
if (value && typeof value === 'object') {
257257
if (!('@protected' in context[key])) {
258258
// Mark terms with object values as protected if they don't have an @protected: false annotation

lib/Util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ export class Util {
156156
* @param value A simple term definition value.
157157
* @param options Options that define the way how expansion must be done.
158158
*/
159-
public static isSimpleTermDefinitionPrefix(value: string, options: IExpandOptions): boolean {
159+
public static isSimpleTermDefinitionPrefix(value: unknown, options: IExpandOptions): boolean {
160160
return !Util.isPotentialKeyword(value)
161-
&& (value[0] === '_' || options.allowPrefixNonGenDelims || Util.isPrefixIriEndingWithGenDelim(value));
161+
&& (options.allowPrefixNonGenDelims || (typeof value === 'string' && (value[0] === '_' || Util.isPrefixIriEndingWithGenDelim(value))));
162162
}
163163

164164
/**

test/ContextParser-test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,21 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
24182418
ERROR_CODES.PROTECTED_TERM_REDEFINITION));
24192419
});
24202420

2421+
it('should error on a protected null term with override', () => {
2422+
return expect(parser.parse([
2423+
{
2424+
"@version": 1.1,
2425+
"@protected": true,
2426+
"term": null
2427+
}, {
2428+
"@version": 1.1,
2429+
"term": {"@id": "http://example.com/term"}
2430+
}
2431+
], { processingMode: 1.1 })).rejects.toThrow(new ErrorCoded(
2432+
'Attempted to override the protected keyword term from null to \"http://example.com/term\"',
2433+
ERROR_CODES.PROTECTED_TERM_REDEFINITION));
2434+
});
2435+
24212436
it('should error on a protected term with override when the overriding version is 1.0', () => {
24222437
return expect(parser.parse([
24232438
{

0 commit comments

Comments
 (0)