From 0c3118a0eaf84ec33b777fc65491b6eb2dded744 Mon Sep 17 00:00:00 2001 From: "David I. Lehn" Date: Fri, 19 May 2023 15:49:12 -0400 Subject: [PATCH] Revert inputFormat change. The `inputFormat` change can break callers that mistakenly pass in an incorrect `inputFormat`. jsonld.js was doing this. Backing this out for now and it will be added to a future major version release. --- CHANGELOG.md | 3 --- lib/index.js | 21 ++++----------------- test/misc.js | 48 ++++-------------------------------------------- 3 files changed, 8 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e403fa..1cf724b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,9 +53,6 @@ by the canonicalization algorithm. This feature is particularly useful when the resulting bnode labels need to be changed for use cases such as selective disclosure. -- Add `inputFormat` option. Use "application/n-quads" for a N-Quads string that - will be parsed. Omit option for a JSON dataset or legacy dataset. This can - simplify a common case of using the internal parser to generate a dataset. ## 3.3.0 - 2022-09-17 diff --git a/lib/index.js b/lib/index.js index 4b13ba9..fef9c91 100644 --- a/lib/index.js +++ b/lib/index.js @@ -43,15 +43,8 @@ try { rdfCanonizeNative = require('rdf-canonize-native'); } catch(e) {} -// return a dataset from input dataset, legacy dataset, or n-quads -function _inputToDataset(input, options) { - if('inputFormat' in options) { - if(options.inputFormat === 'application/n-quads') { - return exports.NQuads.parse(input); - } - throw new Error( - `Unknown canonicalization input format: "${options.inputFormat}".`); - } +// return a dataset from input dataset or legacy dataset +function _inputToDataset(input/*, options*/) { // back-compat with legacy dataset if(!Array.isArray(input)) { return exports.NQuads.legacyDatasetToQuads(input); @@ -81,7 +74,7 @@ exports._rdfCanonizeNative = function(api) { * Asynchronously canonizes an RDF dataset. * * @param {Array|object|string} input - The input to canonize given as a - * dataset, legacy dataset, or format specified by 'inputFormat' option. + * dataset or legacy dataset. * @param {object} options - The options to use: * {string} algorithm - The canonicalization algorithm to use, `URDNA2015`. * {Function} [createMessageDigest] - A factory function for creating a @@ -92,9 +85,6 @@ exports._rdfCanonizeNative = function(api) { * {Map} [canonicalIdMap] - An optional Map to be populated by the canonical * identifier issuer with the bnode identifier mapping generated by the * canonicalization algorithm. - * {string} [inputFormat] - The format of the input. Use - * 'application/n-quads' for a N-Quads string that will be parsed. Omit for - * a JSON dataset or legacy dataset. * {boolean} [useNative=false] - Use native implementation. * {number} [maxDeepIterations=Infinity] - The maximum number of times to run * deep comparison algorithms (such as the N-Degree Hash Quads algorithm @@ -137,7 +127,7 @@ exports.canonize = async function(input, options) { * browser. * * @param {Array|object|string} input - The input to canonize given as a - * dataset, legacy dataset, or format specified by 'inputFormat' option. + * dataset or legacy dataset. * @param {object} options - The options to use: * {string} algorithm - The canonicalization algorithm to use, `URDNA2015`. * {Function} [createMessageDigest] - A factory function for creating a @@ -145,9 +135,6 @@ exports.canonize = async function(input, options) { * implementation used by the canonize algorithm; note that using a hash * algorithm (or HMAC algorithm) that differs from the one specified by * the canonize algorithm will result in different output. - * {string} [inputFormat] - The format of the input. Use - * 'application/n-quads' for a N-Quads string that will be parsed. Omit for - * a JSON dataset or legacy dataset. * {boolean} [useNative=false] - Use native implementation. * {number} [maxDeepIterations=Infinity] - The maximum number of times to run * deep comparison algorithms (such as the N-Degree Hash Quads algorithm diff --git a/test/misc.js b/test/misc.js index be08a51..eb75c4e 100644 --- a/test/misc.js +++ b/test/misc.js @@ -6,49 +6,9 @@ const rdfCanonize = require('..'); const assert = require('assert'); -describe('API tests', () => { - it('should reject invalid inputFormat', async () => { - let error; - try { - await rdfCanonize.canonize('', { - algorithm: 'URDNA2015', - inputFormat: 'application/bogus', - format: 'application/n-quads' - }); - } catch(e) { - error = e; - } - assert(error); - }); - - it('should fail to parse empty dataset as N-Quads', async () => { - let error; - try { - await rdfCanonize.canonize([], { - algorithm: 'URDNA2015', - inputFormat: 'application/bogus', - format: 'application/n-quads' - }); - } catch(e) { - error = e; - } - assert(error); - }); - - it('should fail to parse empty legacy dataset as N-Quads', async () => { - let error; - try { - await rdfCanonize.canonize({}, { - algorithm: 'URDNA2015', - inputFormat: 'application/bogus', - format: 'application/n-quads' - }); - } catch(e) { - error = e; - } - assert(error); - }); +const {NQuads} = rdfCanonize; +describe('API tests', () => { it('should set canonicalIdMap data', async () => { const input = `\ _:b0 _:b1 . @@ -64,9 +24,9 @@ _:c14n1 "v1" . })); const canonicalIdMap = new Map(); - const output = await rdfCanonize.canonize(input, { + const dataset = NQuads.parse(input); + const output = await rdfCanonize.canonize(dataset, { algorithm: 'URDNA2015', - inputFormat: 'application/n-quads', format: 'application/n-quads', canonicalIdMap });