Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/documents.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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());
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/mlutil.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions test-basic/documents-negative.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
49 changes: 49 additions & 0 deletions test-basic/documents-remove-url-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
});
Loading