From e2f2f1bc0c83183005e318d3da4038cd10b674cf Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Fri, 21 Mar 2014 10:45:41 +1100 Subject: [PATCH] Escape illegal xml characters returned by the getgumtreexml command. --- site_ansto/instrument/gumxml.tcl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/site_ansto/instrument/gumxml.tcl b/site_ansto/instrument/gumxml.tcl index 67b5693b..32da525e 100644 --- a/site_ansto/instrument/gumxml.tcl +++ b/site_ansto/instrument/gumxml.tcl @@ -2,13 +2,25 @@ proc getdataType {path} { return [lindex [split [hinfo $path] ,] 0] } +proc encode {str} { + set result [string map -nocase { + {"} {"} + {'} {'} + {<} {<} + {>} {>} + {&} {&} + } $str] + return $result +} + proc make_nodes {path result indent} { set nodename [file tail $path]; set type [getdataType $path] set prefix [string repeat " " $indent] set newIndent [expr $indent + 2] set control "true" - foreach {key value} [string map {= " "} [hlistprop $path tcl]] { + foreach {key rvalue} [string map {= " "} [hlistprop $path tcl]] { + set value [encode $rvalue] if {[string compare -nocase $key "control"] == 0} { if {[string compare -nocase $value "false"] == 0} { set control "false" @@ -30,7 +42,8 @@ set control "true" proc property_elements {path indent} { set prefix [string repeat " " $indent] - foreach {key value} [string map {= " "} [hlistprop $path tcl]] { + foreach {key rvalue} [string map {= " "} [hlistprop $path tcl]] { + set value [encode $rvalue] if {[string compare -nocase $key "control"] == 0} {continue} lappend proplist "$prefix\n" if {[string compare -nocase $key "help"] == 0} {