diff --git a/lib/documents.js b/lib/documents.js index ebe1ec2b..4008c270 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -1,5 +1,5 @@ /* -* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. +* Copyright (c) 2015-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. */ 'use strict'; @@ -1556,11 +1556,11 @@ function removeDocumentImpl(contentOnly, args) { path += '&txid='+mlutil.getTxidParam(txid); } if (temporalCollection != null) { - path += '&temporal-collection='+temporalCollection; + path += '&temporal-collection='+encodeURIComponent(temporalCollection); if (typeof systemTime === 'string' || systemTime instanceof String) { - path += '&system-time='+systemTime; + path += '&system-time='+encodeURIComponent(systemTime); } else if (Object.prototype.toString.call(systemTime) === '[object Date]') { - path += '&system-time='+systemTime.toISOString(); + path += '&system-time='+encodeURIComponent(systemTime.toISOString()); } } diff --git a/lib/mlutil.js b/lib/mlutil.js index e5b453be..97a4dee9 100644 --- a/lib/mlutil.js +++ b/lib/mlutil.js @@ -1,5 +1,5 @@ /* -* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. +* Copyright (c) 2015-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. */ 'use strict'; const util = require('util'); @@ -317,9 +317,9 @@ function getTxidParam(txid, action) { } if (typeof txid === 'string' || txid instanceof String) { - return txid; + return encodeURIComponent(txid); } else if (txid instanceof Transaction) { - return txid.txid; + return encodeURIComponent(txid.txid); } throw new Error( diff --git a/test-basic/documents-negative.js b/test-basic/documents-negative.js index c99aab59..9d1b61f5 100644 --- a/test-basic/documents-negative.js +++ b/test-basic/documents-negative.js @@ -1,5 +1,5 @@ /* -* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. +* Copyright (c) 2015-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. */ var should = require('should'); @@ -92,7 +92,7 @@ describe('document negative', function(){ uri: '/test/negative/writeInvalidTransaction1.txt', contentType: 'text/plain', content: 'the text', - txid: encodeURIComponent('not a real transaction') + txid: 'not a real transaction' }). result(function(response){ response.should.equal('SHOULD HAVE FAILED'); @@ -127,7 +127,7 @@ describe('document negative', function(){ it('should fail to delete a document with a non-existent transaction', function(done){ db.documents.remove({ uris: '/test/negative/deleteInvalidTransaction1.txt', - txid: encodeURIComponent('not a real transaction') + txid: 'not a real transaction' }). result(function(response){ response.should.equal('SHOULD HAVE FAILED'); diff --git a/test-basic/documents-remove-url-test.js b/test-basic/documents-remove-url-test.js new file mode 100644 index 00000000..83a10f61 --- /dev/null +++ b/test-basic/documents-remove-url-test.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2015-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. +*/ +const http = require('http'); +const should = require('should'); +const marklogic = require('../'); + +describe('documents.remove URL parameters', function() { + it('encodes temporal parameters so they cannot add query parameters', function(done) { + let assertionError; + const server = http.createServer(function(request, response) { + try { + request.url.should.containEql('temporal-collection=tc%26uri%3D%2Fx'); + request.url.should.containEql('system-time=2020-01-01T00%3A00%3A00Z%26uri%3D%2Fy'); + request.url.should.containEql('txid=tx%26uri%3D%2Fz'); + request.url.match(/(?:\?|&)uri=/g).should.have.length(1); + } catch (error) { + assertionError = error; + } + response.writeHead(204); + response.end(); + }); + + server.listen(0, '127.0.0.1', function() { + const db = marklogic.createDatabaseClient({ + host: '127.0.0.1', + port: server.address().port, + user: 'u', + password: 'p', + authType: 'basic' + }); + + db.documents.remove({ + uris: '/mine.json', + txid: 'tx&uri=/z', + temporalCollection: 'tc&uri=/x', + systemTime: '2020-01-01T00:00:00Z&uri=/y' + }).result().then(function() { + server.close(function() { + done(assertionError); + }); + }, function(error) { + server.close(function() { + done(assertionError || error); + }); + }); + }); + }); +}); \ No newline at end of file