Skip to content

Commit

Permalink
Url encode apostrophes in params
Browse files Browse the repository at this point in the history
Fix #1246
  • Loading branch information
BrunoCaimar committed Oct 10, 2023
1 parent adf006c commit 140b23f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions spec/Layers/FeatureLayer/FeatureManagerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ describe('L.esri.FeatureManager', function () {
it('should filter features with a where parameter', function () {
server.respondWith(
'GET',
/Type%3D'Active'/g,
/Type%3D%27Active%27/g,
JSON.stringify({
fields: fields,
features: [feature1],
Expand All @@ -662,7 +662,7 @@ describe('L.esri.FeatureManager', function () {

server.respondWith(
'GET',
/Type%3D'Inactive'/g,
/Type%3D%27Inactive%27/g,
JSON.stringify({
fields: fields,
features: [feature2],
Expand Down
14 changes: 14 additions & 0 deletions spec/RequestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,19 @@ describe('L.esri request helpers', function () {
it('should setup an alias for L.esri.post', function () {
expect(L.esri.post).to.be.a('function');
});

it('should encode params for a request with params with apostrophes', function (done) {
const quotedString = "'id123'";

L.esri.request('http://services.arcgisonline.com/ArcGIS/rest/info',
{ id: quotedString }, function (error, response) {
expect(response).to.deep.equal(sampleResponse);
done();
});

const quotedStringEncoded = quotedString.replaceAll("'", '%27');
expect(requests[0].url).to.contain(quotedStringEncoded);
requests[0].respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, JSON.stringify(sampleResponse));
});
});
/* eslint-enable handle-callback-err */
2 changes: 1 addition & 1 deletion spec/Tasks/QuerySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ describe('L.esri.Query', function () {
});

it('should query features with a where option', function (done) {
server.respondWith('GET', featureLayerUrl + 'query?returnGeometry=true&where=NAME%3D\'Site\'&outSR=4326&outFields=*&f=json', JSON.stringify(sampleQueryResponse));
server.respondWith('GET', featureLayerUrl + 'query?returnGeometry=true&where=NAME%3D%27Site%27&outSR=4326&outFields=*&f=json', JSON.stringify(sampleQueryResponse));

task.where('NAME=\'Site\'').run(function (error, featureCollection, raw) {
expect(featureCollection).to.deep.equal(sampleFeatureCollection);
Expand Down
3 changes: 2 additions & 1 deletion src/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function serialize (params) {
}
}

return data;
const APOSTROPHE_URL_ENCODE = '%27';
return data.replaceAll("'", APOSTROPHE_URL_ENCODE);
}

function createRequest (callback, context) {
Expand Down

0 comments on commit 140b23f

Please sign in to comment.