mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-22 07:51:00 +00:00
Properly escape data in the request code
It was only escaping the first quote, all other quotes and other characters that require to be escaped (like line breaks) were not being escaped. JSON.stringify is a good function to handle this.
This commit is contained in:
parent
94c27e3645
commit
64ae20e932
1 changed files with 5 additions and 5 deletions
|
@ -145,9 +145,9 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
return ['const res = await fetch("' + this.BaseUrl + '/translate", {',
|
return ['const res = await fetch("' + this.BaseUrl + '/translate", {',
|
||||||
' method: "POST",',
|
' method: "POST",',
|
||||||
' body: JSON.stringify({',
|
' body: JSON.stringify({',
|
||||||
' q: "' + this.$options.filters.escape(this.inputText) + '",',
|
' q: ' + this.$options.filters.escape(this.inputText) + ',',
|
||||||
' source: "' + this.$options.filters.escape(this.sourceLang) + '",',
|
' source: ' + this.$options.filters.escape(this.sourceLang) + ',',
|
||||||
' target: "' + this.$options.filters.escape(this.targetLang) + '",',
|
' target: ' + this.$options.filters.escape(this.targetLang) + ',',
|
||||||
' format: "' + (this.isHtml ? "html" : "text") + '"',
|
' format: "' + (this.isHtml ? "html" : "text") + '"',
|
||||||
' }),',
|
' }),',
|
||||||
' headers: { "Content-Type": "application/json" }',
|
' headers: { "Content-Type": "application/json" }',
|
||||||
|
@ -167,7 +167,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
},
|
},
|
||||||
filters: {
|
filters: {
|
||||||
escape: function(v){
|
escape: function(v){
|
||||||
return v.replace('"', '\\\"');
|
return JSON.stringify(v);
|
||||||
},
|
},
|
||||||
highlight: function(v){
|
highlight: function(v){
|
||||||
return Prism.highlight(v, Prism.languages.javascript, 'javascript');
|
return Prism.highlight(v, Prism.languages.javascript, 'javascript');
|
||||||
|
|
Loading…
Reference in a new issue