From 93e2785f9f208710d29d1029975a112ffdebe45d Mon Sep 17 00:00:00 2001 From: "David I. Lehn" Date: Wed, 6 Sep 2023 22:31:19 -0400 Subject: [PATCH] Handle unset `rdfDirection` the same as `null`. --- CHANGELOG.md | 5 +++++ lib/toRdf.js | 4 ++-- tests/misc.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2046c8e..a55d89a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # jsonld ChangeLog +## 8.3.1 - 2023-09-xx + +### Fixed +- Handle unset `rdfDirection` the same as `null`. + ## 8.3.0 - 2023-09-06 ### Added diff --git a/lib/toRdf.js b/lib/toRdf.js index f576f6d8..53f20af4 100644 --- a/lib/toRdf.js +++ b/lib/toRdf.js @@ -330,7 +330,7 @@ function _objectToRDF( 'jsonld.InvalidRdfDirection', {value: rdfDirection}); } else if('@language' in item) { - if('@direction' in item && rdfDirection === null) { + if('@direction' in item && !rdfDirection) { if(options.eventHandler) { // FIXME: only emit once? _handleEvent({ @@ -351,7 +351,7 @@ function _objectToRDF( object.datatype.value = datatype || RDF_LANGSTRING; object.language = item['@language']; } else { - if('@direction' in item && rdfDirection === null) { + if('@direction' in item && !rdfDirection) { if(options.eventHandler) { // FIXME: only emit once? _handleEvent({ diff --git a/tests/misc.js b/tests/misc.js index a552d7f9..908052cd 100644 --- a/tests/misc.js +++ b/tests/misc.js @@ -4101,6 +4101,22 @@ _:b0 "v" . }); }); + it('should handle no @lang, @dir, no rdfDirection', async () => { + const input = _json_dir_nl_d; + const nq = _nq_dir_nl_nd; + + await _test({ + type: 'toRDF', + input, + options: {skipExpansion: true}, + expected: nq, + eventCodeLog: [ + 'rdfDirection not set' + ], + testNotSafe: true + }); + }); + it('should handle no @lang, @dir, rdfDirection=null', async () => { const input = _json_dir_nl_d; const nq = _nq_dir_nl_nd;