Skip to content

Commit

Permalink
Only apply language tag lowercasing in 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Mar 16, 2020
1 parent 7a0087b commit 044bd33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ export class Util {
`When an '@language' is set, the value of '@value' must be a string, got '${JSON.stringify(val)}'`);
}

// Language tags are always normalized to lowercase.
valueLanguage = valueLanguage.toLowerCase();
// Language tags are always normalized to lowercase in 1.0.
if (this.parsingContext.activeProcessingMode === 1.0) {
valueLanguage = valueLanguage.toLowerCase();
}

if (!Util.REGEX_LANGUAGE_TAG.test(valueLanguage)) {
if (this.parsingContext.strictRanges) {
Expand Down
17 changes: 13 additions & 4 deletions test/Util-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,19 @@ describe('Util', () => {
.toEqualRdfTerm(literal('abc', 'en-us'));
});

it('with an @value and @language should return a lowercased language-tagged string literal', async () => {
return expect(await util.valueToTerm(context, 'key', { '@value': 'abc', '@language': 'en-US' }, 0))
.toEqualRdfTerm(literal('abc', 'en-us'));
});
it('with an @value and @language should return a lowercased language-tagged string literal in 1.0',
async () => {
util.parsingContext.activeProcessingMode = 1.0;
return expect(await util.valueToTerm(context, 'key', { '@value': 'abc', '@language': 'en-US' }, 0))
.toEqualRdfTerm(literal('abc', 'en-us'));
});

it('with an @value and @language should return a non-lowercased language-tagged string literal in 1.1',
async () => {
util.parsingContext.activeProcessingMode = 1.1;
return expect(await util.valueToTerm(context, 'key', { '@value': 'abc', '@language': 'en-US' }, 0))
.toEqualRdfTerm(literal('abc', 'en-US'));
});

it('with an @value and @type should return a typed literal', async () => {
return expect(await util.valueToTerm(context, 'key', { '@value': 'abc', '@type': 'http://type.com' }, 0))
Expand Down

0 comments on commit 044bd33

Please sign in to comment.