Skip to content
Snippets Groups Projects
Unverified Commit 714bc0fe authored by Piero Toffanin's avatar Piero Toffanin Committed by GitHub
Browse files

Merge pull request #182 from qgustavor/patch-1

Properly escape data in the request code
parents 94c27e36 64ae20e9
No related branches found
No related tags found
No related merge requests found
......@@ -145,9 +145,9 @@ document.addEventListener('DOMContentLoaded', function(){
return ['const res = await fetch("' + this.BaseUrl + '/translate", {',
' method: "POST",',
' body: JSON.stringify({',
' q: "' + this.$options.filters.escape(this.inputText) + '",',
' source: "' + this.$options.filters.escape(this.sourceLang) + '",',
' target: "' + this.$options.filters.escape(this.targetLang) + '",',
' q: ' + this.$options.filters.escape(this.inputText) + ',',
' source: ' + this.$options.filters.escape(this.sourceLang) + ',',
' target: ' + this.$options.filters.escape(this.targetLang) + ',',
' format: "' + (this.isHtml ? "html" : "text") + '"',
' }),',
' headers: { "Content-Type": "application/json" }',
......@@ -167,7 +167,7 @@ document.addEventListener('DOMContentLoaded', function(){
},
filters: {
escape: function(v){
return v.replace('"', '\\\"');
return JSON.stringify(v);
},
highlight: function(v){
return Prism.highlight(v, Prism.languages.javascript, 'javascript');
......@@ -407,4 +407,4 @@ function setApiKey(){
localStorage.setItem("api_key", newKey);
}
// @license-end
\ No newline at end of file
// @license-end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment