Skip to content

Commit 48fc054

Browse files
committed
Added URL encode to path params, query params and the API key as a query param
1 parent b5104c4 commit 48fc054

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/components/api-request.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export default class ApiRequest extends LitElement {
466466
}
467467
//Generate URL using Path Params
468468
pathParamEls.map(function(el){
469-
fetchUrl = fetchUrl.replace("{"+el.dataset.pname+"}", el.value);
469+
fetchUrl = fetchUrl.replace("{"+el.dataset.pname+"}", encodeURIComponent(el.value));
470470
});
471471

472472
//Submit Query Params
@@ -475,13 +475,13 @@ export default class ApiRequest extends LitElement {
475475
queryParamEls.map(function(el){
476476
if (el.dataset.array==='false'){
477477
if (el.value !== ''){
478-
queryParam.append(el.dataset.pname, el.value);
478+
queryParam.append(el.dataset.pname, encodeURIComponent(el.value));
479479
}
480480
}
481481
else {
482482
let vals = el.getValues();
483483
for(let v of vals){
484-
queryParam.append(el.dataset.pname, v);
484+
queryParam.append(el.dataset.pname, encodeURIComponent(v));
485485
}
486486
}
487487
})
@@ -490,7 +490,7 @@ export default class ApiRequest extends LitElement {
490490

491491
// Add authentication Query-Param if provided
492492
if (this.apiKeyValue && this.apiKeyName && this.apiKeyLocation==='query'){
493-
fetchUrl = `${fetchUrl}&${this.apiKeyName}=${this.apiKeyValue}`;
493+
fetchUrl = `${fetchUrl}&${this.apiKeyName}=${encodeURIComponent(this.apiKeyValue)}`;
494494
}
495495

496496
//Final URL for API call

0 commit comments

Comments
 (0)