[431913] Remove invalid XML Unicode characters and fix linefeed
escaping.

Change-Id: I24ea1e95eb1d4bb846ecefff420118a13b42abf4
Signed-off-by: Carsten Karbach <c.karbach@fz-juelich.de>
diff --git a/rms/org.eclipse.ptp.rm.lml.da/LML_combiner/LML_combine_file_obj.pm b/rms/org.eclipse.ptp.rm.lml.da/LML_combiner/LML_combine_file_obj.pm
index e1db25b..4dedcc4 100644
--- a/rms/org.eclipse.ptp.rm.lml.da/LML_combiner/LML_combine_file_obj.pm
+++ b/rms/org.eclipse.ptp.rm.lml.da/LML_combiner/LML_combine_file_obj.pm
@@ -257,12 +257,14 @@
 	$result =~ s/&gt;/>/g;
 	$result =~ s/&quot;/"/g;
 	$result =~ s/&apos;/'/g;
+	$result =~ s/\&\#10;/\n/gs;
 	#Now escape all special characters in the result string
 	$result =~ s/&/&amp;/g;
 	$result =~ s/</&lt;/g;
 	$result =~ s/>/&gt;/g;
 	$result =~ s/"/&quot;/g;
 	$result =~ s/'/&apos;/g;
+	$result =~ s/\n/\&\#10;/gs;
 	
 	return $result;
 }
diff --git a/rms/org.eclipse.ptp.rm.lml.da/lib/LML_da_util.pm b/rms/org.eclipse.ptp.rm.lml.da/lib/LML_da_util.pm
index 0d51193..881fc6f 100644
--- a/rms/org.eclipse.ptp.rm.lml.da/lib/LML_da_util.pm
+++ b/rms/org.eclipse.ptp.rm.lml.da/lib/LML_da_util.pm
@@ -364,14 +364,32 @@
 # @return passed string with escaped XML special characters
 #***************************************************************************
 sub escapeForXML{
+	no warnings "utf8";#Ignore the warnings as the entire UTF8 range is required for the range checks
 	my $result = shift;
 	$result =~ s/&/&amp;/g;
+	$result =~ s/\n/\&\#10;/gs;
 	$result =~ s/</&lt;/g;
 	$result =~ s/>/&gt;/g;
 	$result =~ s/"/&quot;/g;
 	$result =~ s/'/&apos;/g;
-	
-	return $result;
+	#Exclude invalid Unicode characters,
+	#examples are thos characters marking the coloring for the console outputs
+	#see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char for definition of allowed XML characters
+	my @chars = split('', $result);
+	my $finalResult = "";
+
+	for(my $i=0;$i<= $#chars; $i++){
+		my $current = $chars[$i];
+		if (($current eq "\N{U+0009}") ||
+	        ($current eq "\N{U+000A}") ||
+	        ($current eq "\N{U+000D}") ||
+	        (($current ge "\N{U+0020}") && ($current le "\N{U+D7FF}")) ||
+	        (($current ge "\N{U+E000}") && ($current le "\N{U+FFFD}")) ||
+	        (($current ge "\N{U+10000}") && ($current le "\N{U+10FFFF}"))){
+	        $finalResult.= $current;
+		}
+	}
+	return $finalResult;
 }
 
 1;
diff --git a/rms/org.eclipse.ptp.rm.lml.da/rms/PBS/da_system_info_LML.pl b/rms/org.eclipse.ptp.rm.lml.da/rms/PBS/da_system_info_LML.pl
index 2fe6ac3..574dce8 100755
--- a/rms/org.eclipse.ptp.rm.lml.da/rms/PBS/da_system_info_LML.pl
+++ b/rms/org.eclipse.ptp.rm.lml.da/rms/PBS/da_system_info_LML.pl
@@ -125,11 +125,6 @@
     my($key,$mkey,$value)=@_;
     my $ret=$value;
 
-    if($mkey eq "motd") {
-	$ret = escapeForXML($ret);
-	$ret=~s/\n/\&\#10;/gs;
-    }
-
     return($ret);
 }
 
diff --git a/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE/da_system_info_LML.pl b/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE/da_system_info_LML.pl
index aca8f7b..0f08ae2 100755
--- a/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE/da_system_info_LML.pl
+++ b/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE/da_system_info_LML.pl
@@ -114,16 +114,6 @@
     my($key,$mkey,$value)=@_;
     my $ret=$value;
 
-    if($mkey eq "motd") {
-#	$ret=~s/\&/&amp;/gs;
-	$ret=~s/\n/\&\#10;/gs;
-        $ret=~s/</\&lt;/gs;
-        $ret=~s/>/\&gt;/gs;
-        $ret=~s/\&/\&amp;/gs;
-        $ret=~s/'/\&apos;/gs;
-        $ret=~s/"/\&quot;/gs;
-    }
-
     return($ret);
 }
 
diff --git a/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE_ALPS/da_system_info_LML.pl b/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE_ALPS/da_system_info_LML.pl
index aca427f..c1510fc 100755
--- a/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE_ALPS/da_system_info_LML.pl
+++ b/rms/org.eclipse.ptp.rm.lml.da/rms/TORQUE_ALPS/da_system_info_LML.pl
@@ -114,15 +114,6 @@
     my($key,$mkey,$value)=@_;
     my $ret=$value;
 
-    if($mkey eq "motd") {
-        $ret=~s/</\&lt;/gs;
-        $ret=~s/>/\&gt;/gs;
-        $ret=~s/\&/\&amp;/gs;
-        $ret=~s/'/\&apos;/gs;
-        $ret=~s/"/\&quot;/gs;
-        $ret=~s/\n/\&\#10;/gs;
-    }
-
     return($ret);
 }