Use attr() instead of data() to prevent parsing of json (#2548)

* Use attr() instead of data() to prevent parsing of json

A fix for issue #2503 
Valid JSON text will be converted to a JSON object, not text , when using .data(). using .attr() prevents this behavior.

* Update gitbucket.js

Use different methods to get old and head values depending on the object type
This commit is contained in:
Marcel Berteler
2020-11-03 09:25:47 +02:00
committed by GitHub
parent d97f7c6025
commit f25cf5781c

View File

@@ -77,10 +77,12 @@ function displayErrors(data, elem){
*/ */
function diffUsingJS(oldTextId, newTextId, outputId, viewType, ignoreSpace) { function diffUsingJS(oldTextId, newTextId, outputId, viewType, ignoreSpace) {
var old = $('#' + oldTextId), head = $('#' + newTextId); var old = $('#' + oldTextId), head = $('#' + newTextId);
old.is("textarea") ? (oldTextValue = old.data('val')) : (oldTextValue = old.attr('data-val'));
head.is("textarea") ? (headTextvalue = head.data('val')) : (headTextValue = head.attr('data-val'));
var render = new JsDiffRender({ var render = new JsDiffRender({
oldText : old.data('val'), oldText : oldTextValue,
oldTextName: old.data('file-name'), oldTextName: old.data('file-name'),
newText : head.data('val'), newText : headTextValue,
newTextName: head.data('file-name'), newTextName: head.data('file-name'),
ignoreSpace: ignoreSpace, ignoreSpace: ignoreSpace,
contextSize: 4 contextSize: 4