Fix bug with text for nodes. Add escaping symbols.

This commit is contained in:
Unick Soft 2020-08-19 20:45:26 +02:00
parent f068ee2a32
commit 475f4ea88b
6 changed files with 36 additions and 16 deletions

View File

@ -1474,20 +1474,12 @@ Application.prototype.LoadUserSettings = function(json)
Application.prototype.EncodeToHTML = function (str) Application.prototype.EncodeToHTML = function (str)
{ {
return str.replace(/&/g, '&') return gEncodeToHTML(str);
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
} }
Application.prototype.DecodeFromHTML = function (str) Application.prototype.DecodeFromHTML = function (str)
{ {
return str.replace(/&apos;/g, "'") return gDecodeFromHTML(str);
.replace(/&quot;/g, '"')
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&');
} }
Application.prototype.SetVertexStyle = function (index, style) Application.prototype.SetVertexStyle = function (index, style)

View File

@ -54,8 +54,8 @@ BaseEdge.prototype.SaveToXML = function ()
"weight=\"" + this.weight + "\" " + "weight=\"" + this.weight + "\" " +
"useWeight=\"" + this.useWeight + "\" " + "useWeight=\"" + this.useWeight + "\" " +
"id=\"" + this.id + "\" " + "id=\"" + this.id + "\" " +
"text=\"" + this.text + "\" " + "text=\"" + gEncodeToHTML(this.text) + "\" " +
"upText=\"" + this.upText + "\" " + "upText=\"" + gEncodeToHTML(this.upText) + "\" " +
"arrayStyleStart=\"" + this.arrayStyleStart + "\" " + "arrayStyleStart=\"" + this.arrayStyleStart + "\" " +
"arrayStyleFinish=\"" + this.arrayStyleFinish + "\" " + "arrayStyleFinish=\"" + this.arrayStyleFinish + "\" " +
this.model.SaveToXML() + this.model.SaveToXML() +
@ -85,7 +85,7 @@ BaseEdge.prototype.LoadFromXML = function (xml, graph)
this.hasPair = xml.attr('hasPair') == "true"; this.hasPair = xml.attr('hasPair') == "true";
this.useWeight = xml.attr('useWeight') == "true"; this.useWeight = xml.attr('useWeight') == "true";
this.id = xml.attr('id'); this.id = xml.attr('id');
this.text = xml.attr("text") == null ? "" : xml.attr("text"); this.text = xml.attr("text") == null ? "" : gDecodeFromHTML(xml.attr("text"));
this.arrayStyleStart = xml.attr("arrayStyleStart") == null ? "" : xml.attr("arrayStyleStart"); this.arrayStyleStart = xml.attr("arrayStyleStart") == null ? "" : xml.attr("arrayStyleStart");
this.arrayStyleFinish = xml.attr("arrayStyleFinish") == null ? "" : xml.attr("arrayStyleFinish"); this.arrayStyleFinish = xml.attr("arrayStyleFinish") == null ? "" : xml.attr("arrayStyleFinish");
this.upText = xml.attr('upText'); this.upText = xml.attr('upText');
@ -93,6 +93,10 @@ BaseEdge.prototype.LoadFromXML = function (xml, graph)
{ {
this.upText = ""; this.upText = "";
} }
else
{
this.upText = gDecodeFromHTML(this.upText);
}
this.model.LoadFromXML(xml); this.model.LoadFromXML(xml);
} }

View File

@ -34,8 +34,8 @@ BaseVertex.prototype.SaveToXML = function ()
"positionX=\"" + this.position.x + "\" " + "positionX=\"" + this.position.x + "\" " +
"positionY=\"" + this.position.y + "\" " + "positionY=\"" + this.position.y + "\" " +
"id=\"" + this.id + "\" " + "id=\"" + this.id + "\" " +
"mainText=\"" + this.mainText + "\" " + "mainText=\"" + gEncodeToHTML(this.mainText) + "\" " +
"upText=\"" + this.upText + "\" " + "upText=\"" + gEncodeToHTML(this.upText) + "\" " +
"></node>"; "></node>";
} }
@ -52,8 +52,13 @@ BaseVertex.prototype.LoadFromXML = function (xml)
if (typeof this.mainText === 'undefined') if (typeof this.mainText === 'undefined')
this.mainText = this.id; this.mainText = this.id;
else
this.mainText = gDecodeFromHTML(this.mainText);
if (typeof this.upText === 'undefined') if (typeof this.upText === 'undefined')
this.upText = ""; this.upText = "";
else
this.upText = gDecodeFromHTML(this.upText);
} }
BaseVertex.prototype.SetId = function (id) BaseVertex.prototype.SetId = function (id)

View File

@ -3,6 +3,7 @@ $outputFilename = 'example.js';
unlink($outputFilename); unlink($outputFilename);
file_put_contents($outputFilename, file_get_contents("utils.js"), FILE_APPEND);
file_put_contents($outputFilename, file_get_contents("texts.js"), FILE_APPEND); file_put_contents($outputFilename, file_get_contents("texts.js"), FILE_APPEND);
file_put_contents($outputFilename, file_get_contents("point.js"), FILE_APPEND); file_put_contents($outputFilename, file_get_contents("point.js"), FILE_APPEND);
file_put_contents($outputFilename, file_get_contents("EdgeModel.js"), FILE_APPEND); file_put_contents($outputFilename, file_get_contents("EdgeModel.js"), FILE_APPEND);

18
script/utils.js Normal file
View File

@ -0,0 +1,18 @@
function gEncodeToHTML(str)
{
return str.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
}
function gDecodeFromHTML(str)
{
return str.replace(/&apos;/g, "'")
.replace(/&quot;/g, '"')
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&');
}

View File

@ -10,7 +10,7 @@
<script src="<?= Root('i/js/dev/jquery-ui.js')?>"></script> <script src="<?= Root('i/js/dev/jquery-ui.js')?>"></script>
<script src="<?= Root('i/js/dev/jquery.feedback_me.js')?>"></script> <script src="<?= Root('i/js/dev/jquery.feedback_me.js')?>"></script>
<script src="<?= Root("script/example.js?v=29")?>" ></script> <script src="<?= Root("script/example.js?v=30")?>" ></script>
</head> </head>
<!-- <!--
<div class="pull-right"> <div class="pull-right">