Skip to content

Commit 499646e

Browse files
committed
Sort @type when looking for scoped contexts.
Adapted from: ruby-rdf/json-ld@3293841
1 parent 96ca9b1 commit 499646e

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Fixed
44
- Use rdf-canonize to compare n-quads test results.
55
- Multiple graph tests.
6+
- Sort `@type` when looking for scoped contexts.
67

78
### Changed
89
- Use JSON-LD WG tests.

lib/compact.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ api.compact = ({
145145
// apply any context defined on an alias of @type
146146
// if key is @type and any compacted value is a term having a local
147147
// context, overlay that context
148-
const types = element['@type'] || [];
148+
let types = element['@type'] || [];
149+
if(types.length > 1) {
150+
types = Array.from(types).sort();
151+
}
149152
for(const type of types) {
150153
const compactedType = api.compactIri(
151154
{activeCtx, iri: type, relativeTo: {vocab: true}});

lib/expand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ api.expand = ({
157157
const expandedProperty = _expandIri(activeCtx, key, {vocab: true});
158158
if(expandedProperty === '@type') {
159159
// set scopped contexts from @type
160-
const types = [].concat(element[key]);
160+
const types = [].concat(element[key]).sort();
161161
for(const type of types) {
162162
const ctx = _getContextValue(activeCtx, type, '@context');
163163
if(ctx) {

tests/test-common.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ const TEST_TYPES = {
4444
/^#tli05/,
4545
// terms
4646
/^#tp001/,
47-
// scoped context on type
48-
/^#tc012/,
4947
// rel iri
5048
/^#t0095/
5149
]
@@ -76,8 +74,6 @@ const TEST_TYPES = {
7674
// mode
7775
/^#tp001/,
7876
/^#tp002/,
79-
// scoped context on type
80-
/^#tc011/,
8177
// rel iri
8278
/^#t0092/,
8379
// remote

0 commit comments

Comments
 (0)