Browse Source

AMBARI-5160 Error in picking up LzoCodecs in Ambari-deployed Oracle 6.3 and CentOS5. (ababiichuk)

aBabiichuk 11 years ago
parent
commit
442f73229d

+ 1 - 1
ambari-web/app/controllers/main/mirroring/jobs_controller.js

@@ -163,7 +163,7 @@ App.MainDatasetJobsController = Em.Controller.extend({
   openInfoInNewTab: function (xml) {
     var newWindow = window.open('');
     var newDocument = newWindow.document;
-    newDocument.write('<pre>' + App.config.escapeXMLCharacters(xml) + '</pre>');
+    newDocument.write('<pre>' + App.config.escapeXMLCharacters(xml, true) + '</pre>');
     newWindow.focus();
   },
 

+ 8 - 4
ambari-web/app/utils/config.js

@@ -57,16 +57,20 @@ App.config = Em.Object.create({
    * Special characters in XML are defined at
    * http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
    */
-  escapeXMLCharacters: function(value) {
+  escapeXMLCharacters: function(value, toXML) {
     var self = this;
     // To prevent double/triple replacing '&gt;' to '&amp;gt;' to '&amp;amp;gt;', we need
     // to first unescape all XML chars, and then escape them again.
     var newValue = String(value).replace(/(&amp;|&lt;|&gt;|&quot;|&apos;)/g, function (s) {
       return self.xmlUnEscapeMap[s];
     });
-    return String(newValue).replace(/[&<>"']/g, function (s) {
-      return self.xmlEscapeMap[s];
-    });
+    if (toXML) {
+      return String(newValue).replace(/[&<>"']/g, function (s) {
+        return self.xmlEscapeMap[s];
+      });
+    } else {
+      return newValue;
+    }
   },
   preDefinedServiceConfigs: function () {
     var configs = this.get('preDefinedGlobalProperties');

+ 32 - 0
ambari-web/test/utils/config_test.js

@@ -230,4 +230,36 @@ describe('App.config', function () {
       expect(result.length).to.equal(1);
     });
   });
+
+  describe('#escapeXMLCharacters', function () {
+
+    var testConfigs = [
+      {
+        html: '&>"',
+        json: '&>"'
+      },
+      {
+        html: '&amp;&gt;&quot;&apos;',
+        json: '&>"\''
+      },
+      {
+        html: '&&gt;',
+        json: '&>'
+      },
+      {
+        html: '&&&amp;',
+        json: '&&&'
+      },
+      {
+        html: 'LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/lib/native/`$JAVA_HOME/bin/java -d32 -version &amp;&gt; /dev/null;if [ $? -eq 0 ]; then echo Linux-i386-32; else echo Linux-amd64-64;fi`',
+        json: 'LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/lib/native/`$JAVA_HOME/bin/java -d32 -version &> /dev/null;if [ $? -eq 0 ]; then echo Linux-i386-32; else echo Linux-amd64-64;fi`'
+      }
+    ];
+    testConfigs.forEach(function(t){
+      it('parsing html ' + t.html, function () {
+        expect(t.json).to.equal(App.config.escapeXMLCharacters(t.html));
+      });
+    });
+
+  });
 });