Skip to content

Commit b01040d

Browse files
committed
Fix literal with empty direction not equaling undefined direction
1 parent ee9c7e4 commit b01040d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/Literal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export class Literal implements RDF.Literal {
4949

5050
public equals(other?: RDF.Term | null): boolean {
5151
return !!other && other.termType === 'Literal' && other.value === this.value &&
52-
other.language === this.language && other.direction === this.direction &&
52+
other.language === this.language &&
53+
((other.direction === this.direction) || (!other.direction && this.direction === '')) &&
5354
this.datatype.equals(other.datatype);
5455
}
5556
}

test/DataFactory-test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ describe('DataFactory', () => {
138138

139139
expect(factory.literal('a', { language: 'en-us', direction: 'ltr' })
140140
.equals(factory.literal('a', { language: 'en-us', direction: 'ltr' }))).toEqual(true);
141+
// Simulate old data factory before base direction existed
142+
const literalNullDirection = factory.literal('a', 'en-us');
143+
(<any> literalNullDirection).direction = undefined;
144+
expect(factory.literal('a', { language: 'en-us', direction: '' })
145+
.equals(literalNullDirection)).toEqual(true);
141146

142147
expect(factory.literal('a')
143148
.equals(factory.literal('a', 'en-us'))).toEqual(false);

0 commit comments

Comments
 (0)