Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url encode apostrophes in request params #1377

Merged
merged 1 commit into from
Nov 21, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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