You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2015/03/18 04:21:33 UTC

[27/28] incubator-nifi git commit: NIFI-353: - Modifying the hexview plugin to address html escape issues and no longer rendering the base64 padding characters.

NIFI-353:
- Modifying the hexview plugin to address html escape issues and no longer rendering the base64 padding characters.

Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/4c448436
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/4c448436
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/4c448436

Branch: refs/heads/NIFI-353
Commit: 4c448436c5f84ac5bd4b3afad1b75f40c45c6d54
Parents: 1a05c9d
Author: Matt Gilman <ma...@gmail.com>
Authored: Tue Mar 17 23:20:24 2015 -0400
Committer: Matt Gilman <ma...@gmail.com>
Committed: Tue Mar 17 23:20:24 2015 -0400

----------------------------------------------------------------------
 .../src/main/webapp/WEB-INF/jsp/hexview.jsp     |   3 +-
 .../src/main/webapp/js/hexview/hexview.js       | 374 ++++++++++---------
 2 files changed, 201 insertions(+), 176 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4c448436/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp
index 783c18e..872d8ea 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp
@@ -24,7 +24,8 @@
     <form id="hexviewwindow_params">
         <input type="hidden" name="highlights" value="" />
         <input type="hidden" name="row_width" value="16" />
-        <input type="hidden" name="word_size" value="2" />
+        <input type="hidden" name="word_size" value="1" />
+        <input type="hidden" name="hide_0x" value="1" />
         <input type="hidden" name="caption" value="" />
     </form>
 </div>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4c448436/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/js/hexview/hexview.js
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/js/hexview/hexview.js b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/js/hexview/hexview.js
index c5b4401..7c461d5 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/js/hexview/hexview.js
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/js/hexview/hexview.js
@@ -1,175 +1,199 @@
-		var HEX = '0123456789ABCDEF'
-
-		function dec2_to_hex(dec)
-		{
-			if (dec < 0)
-				dec = 0
-			
-			if (dec > 255)
-				dec = 255
-			
-			return HEX.charAt(Math.floor(dec / 16)) + HEX.charAt(dec % 16)
-		}
-		
-		function dec_to_hex8(dec)
-		{
-			var str = ""
-			
-			for (var i = 3; i >= 0; i--)
-			{
-				str += dec2_to_hex((dec >> (i*8)) & 255)
-			}
-			
-			return str;
-		}
-
-		function remove_whitespace(str)
-		{
-			return str.replace(/\n/g, "")
-					  .replace(/\t/g, "")
-					  .replace(/ /g, "")
-					  .replace(/\r/g, "")
-		}
-		
-		var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
-		
-		function base64_decode(encoded)
-		{
-			var decoded = ""
-			
-			for (var i = 0; i < encoded.length; i += 4)
-			{
-				var ch0 = encoded.charAt(i+0)
-				var ch1 = encoded.charAt(i+1)
-				var ch2 = encoded.charAt(i+2)
-				var ch3 = encoded.charAt(i+3)
-				
-				var index0 = BASE64_CHARS.indexOf(ch0);
-				var index1 = BASE64_CHARS.indexOf(ch1);
-				var index2 = BASE64_CHARS.indexOf(ch2);
-				var index3 = BASE64_CHARS.indexOf(ch3);
-				
-				decoded += String.fromCharCode((index0 << 2) | (index1 >> 4))
-				decoded += String.fromCharCode(((index1 & 15) << 4) | (index2 >> 2))
-				decoded += String.fromCharCode(((index2 & 3) << 6) | index3)
-			}
-			
-			return decoded
-		}
-		
-		function markup_hexviewwindow(div, index)
-		{
-			var bin_data = base64_decode(remove_whitespace(div.text()))
-			var line_data
-			var title = div.attr("title")
-			
-			var highlights_str = $("form#hexviewwindow_params input[name='highlights']", div).attr("value").split(',')
-			var highlights = []
-			
-			for (var i = 0; i < highlights_str.length; i++)
-			{
-				highlights.push(highlights_str[i].split(":"))
-			}
-			 
-			var params = title.split(':')
-			var step = parseInt($("form#hexviewwindow_params input[name='row_width']", div).attr("value"))
-			var word_size = parseInt($("form#hexviewwindow_params input[name='word_size']", div).attr("value"))
-			var hide_0x = parseInt($("form#hexviewwindow_params input[name='hide_0x']", div).attr("value"))
-			var decimal_offset = parseInt($("form#hexviewwindow_params input[name='decimal_offset']", div).attr("value"))
-			var start_byte_1 = parseInt($("form#hexviewwindow_params input[name='start_byte_1']", div).attr("value"))
-			var caption = $("form#hexviewwindow_params input[name='caption']", div).attr("value")
-			
-			div.text("")
-			div.append("<table></table>")
-			
-			var offset = (start_byte_1 ? 1 : 0)
-
-			function apply_highlights(index)
-			{
-				for (var j = 0; j < highlights.length; j++)
-				{
-					if ((index >= highlights[j][0]) && (index <= highlights[j][1]))
-					{
-						if (index == highlights[j][0])
-						{
-							$("table tr td:last", div).addClass("hexviewerwindow_border_start")
-						}
-						
-						if (index == highlights[j][1])
-						{
-							$("table tr td:last", div).addClass("hexviewerwindow_border_end")
-						}
-						
-						$("table tr td:last", div).addClass("hexviewerwindow_code_hi hexviewerwindow_border_middle")
-						$("table tr td:last", div).attr("style", "background-color: " + highlights[j][2] + ";")
-						$("table tr td:last", div).attr("title", highlights[j][3])
-						
-						runlen += 1
-					}
-					else
-					{
-						$("table tr td:last", div).addClass("hexviewerwindow_code")
-					}
-				}
-			}
-
-			if (caption)
-				$("table", div).append("<caption>" + caption + "</caption>")
-				
-			while (bin_data.length > 0)
-			{
-				line_data = bin_data.slice(0, step)
-				bin_data = bin_data.slice(step)
-			
-				$("table", div).addClass("hexviewerwindow_table")
-				$("table", div).append("<tr></tr>").addClass("hexviewerwindow")
-				$("table tr:last", div).append("<td>" + (decimal_offset ? ("00000000"+offset).slice(-8) : "0x" + dec_to_hex8(offset)) + "</td>")
-				$("table tr td:last", div).addClass("hexviewerwindow_offset")
-				
-				var runlen = 0
-				
-				for (var i = 0; i < line_data.length; i += word_size)
-				{
-					var num = ""
-					
-					for (var j = 0; j < word_size; j++)
-					{
-						num += dec2_to_hex(line_data.charCodeAt(i+j))
-					}
-					
-					$("table tr:last", div).append("<td>" + (hide_0x ? "" : "0x") + num + "</td>")
-
-					apply_highlights(offset+i)
-				}
-				
-				var text = ""
-				
-				for (var i = 0; i < line_data.length; i++)
-				{
-					var cc = line_data.charCodeAt(i)
-					
-					if ((cc >= 32) && (cc <= 126))
-					{
-						text = text + line_data.charAt(i)
-					}
-					else
-					{
-						text = text + "."
-					}
-				}
-				
-				if (line_data.length < step)
-					$("table tr td:last", div).attr("colspan", Math.floor((step - line_data.length) / word_size) + 1)
-
-				offset += step
-				
-				$("table tr:last", div).append("<td>" + text + "</td>")
-				$("table tr td:last", div).addClass("hexviewerwindow_visual")
-			}
-		}
-		
-		$(document).ready(function () {
-			$("div.hexviewwindow").each(function (index) {
-				markup_hexviewwindow($(this), index)
-			})
-		})
\ No newline at end of file
+$(document).ready(function () {
+    var HEX = '0123456789ABCDEF';
+
+    function dec2_to_hex(dec)
+    {
+        if (dec < 0)
+            dec = 0;
+
+        if (dec > 255)
+            dec = 255;
+
+        return HEX.charAt(Math.floor(dec / 16)) + HEX.charAt(dec % 16);
+    }
+
+    function dec_to_hex8(dec)
+    {
+        var str = "";
+
+        for (var i = 3; i >= 0; i--)
+        {
+            str += dec2_to_hex((dec >> (i*8)) & 255);
+        }
+
+        return str;
+    }
+
+    function remove_whitespace(str)
+    {
+        return str.replace(/\n/g, "")
+                  .replace(/\t/g, "")
+                  .replace(/ /g, "")
+                  .replace(/\r/g, "");
+    }
+
+    var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+
+    function base64_decode(encoded)
+    {
+        var decoded = "";
+
+        for (var i = 0; i < encoded.length; i += 4)
+        {
+            var ch0 = encoded.charAt(i+0);
+            var ch1 = encoded.charAt(i+1);
+            var ch2 = encoded.charAt(i+2);
+            var ch3 = encoded.charAt(i+3);
+
+            var index0 = BASE64_CHARS.indexOf(ch0);
+            var index1 = BASE64_CHARS.indexOf(ch1);
+            var index2 = BASE64_CHARS.indexOf(ch2);
+            var index3 = BASE64_CHARS.indexOf(ch3);
+
+            decoded += String.fromCharCode((index0 << 2) | (index1 >> 4));
+            decoded += String.fromCharCode(((index1 & 15) << 4) | (index2 >> 2));
+            
+            // skip the base64 padding as those weren't present in the actual bytes
+            var token = String.fromCharCode(((index2 & 3) << 6) | index3);
+            if (index3 !== 64 || token !== '@') {
+                decoded += token;
+            }
+        }
+
+        return decoded;
+    }
+
+    function markup_hexviewwindow(div, index)
+    {
+        var entityMap = {
+            '&': '&amp;',
+            '<': '&lt;',
+            '>': '&gt;',
+            '"': '&quot;',
+            "'": '&#39;',
+            '/': '&#x2f;'
+        };
+
+        function escapeHtml(string) {
+            if (string === null || typeof string === 'undefined') {
+                return '';
+            } else {
+                return String(string).replace(/[&<>"'\/]/g, function (s) {
+                    return entityMap[s];
+                });
+            }
+        }
+
+        var bin_data = base64_decode(remove_whitespace(div.text()));
+        var line_data;
+        var title = div.attr("title");
+
+        var highlights_str = $("form#hexviewwindow_params input[name='highlights']", div).attr("value").split(',');
+        var highlights = [];
+
+        for (var i = 0; i < highlights_str.length; i++)
+        {
+            highlights.push(highlights_str[i].split(":"));
+        }
+
+        var params = title.split(':');
+        var step = parseInt($("form#hexviewwindow_params input[name='row_width']", div).attr("value"));
+        var word_size = parseInt($("form#hexviewwindow_params input[name='word_size']", div).attr("value"));
+        var hide_0x = parseInt($("form#hexviewwindow_params input[name='hide_0x']", div).attr("value"));
+        var decimal_offset = parseInt($("form#hexviewwindow_params input[name='decimal_offset']", div).attr("value"));
+        var start_byte_1 = parseInt($("form#hexviewwindow_params input[name='start_byte_1']", div).attr("value"));
+        var caption = $("form#hexviewwindow_params input[name='caption']", div).attr("value");
+
+        div.text("");
+        div.append("<table></table>");
+
+        var offset = (start_byte_1 ? 1 : 0);
+
+        function apply_highlights(index)
+        {
+            for (var j = 0; j < highlights.length; j++)
+            {
+                if ((index >= highlights[j][0]) && (index <= highlights[j][1]))
+                {
+                    if (index === highlights[j][0])
+                    {
+                        $("table tr td:last", div).addClass("hexviewerwindow_border_start");
+                    }
+
+                    if (index === highlights[j][1])
+                    {
+                        $("table tr td:last", div).addClass("hexviewerwindow_border_end");
+                    }
+
+                    $("table tr td:last", div).addClass("hexviewerwindow_code_hi hexviewerwindow_border_middle");
+                    $("table tr td:last", div).attr("style", "background-color: " + highlights[j][2] + ";");
+                    $("table tr td:last", div).attr("title", highlights[j][3]);
+
+                    runlen += 1;
+                }
+                else
+                {
+                    $("table tr td:last", div).addClass("hexviewerwindow_code");
+                }
+            }
+        }
+
+        if (caption)
+            $("table", div).append("<caption>" + escapeHtml(caption) + "</caption>");
+
+        while (bin_data.length > 0)
+        {
+            line_data = bin_data.slice(0, step);
+            bin_data = bin_data.slice(step);
+
+            $("table", div).addClass("hexviewerwindow_table");
+            $("table", div).append("<tr></tr>").addClass("hexviewerwindow");
+            $("table tr:last", div).append("<td>" + (decimal_offset ? ("00000000"+offset).slice(-8) : "0x" + dec_to_hex8(offset)) + "</td>");
+            $("table tr td:last", div).addClass("hexviewerwindow_offset");
+
+            var runlen = 0;
+
+            for (var i = 0; i < line_data.length; i += word_size)
+            {
+                var num = "";
+
+                for (var j = 0; j < word_size; j++)
+                {
+                    num += dec2_to_hex(line_data.charCodeAt(i+j));
+                }
+
+                $("table tr:last", div).append("<td>" + (hide_0x ? "" : "0x") + num + "</td>");
+
+                apply_highlights(offset+i);
+            }
+
+            var text = "";
+
+            for (var i = 0; i < line_data.length; i++)
+            {
+                var cc = line_data.charCodeAt(i);
+
+                if ((cc >= 32) && (cc <= 126))
+                {
+                    text = text + line_data.charAt(i);
+                }
+                else
+                {
+                    text = text + ".";
+                }
+            }
+
+            if (line_data.length < step)
+                $("table tr td:last", div).attr("colspan", Math.floor((step - line_data.length) / word_size) + 1);
+
+            offset += step;
+
+            $("table tr:last", div).append("<td>" + escapeHtml(text) + "</td>");
+            $("table tr td:last", div).addClass("hexviewerwindow_visual");
+        }
+    }
+
+    $("div.hexviewwindow").each(function (index) {
+        markup_hexviewwindow($(this), index);
+    });
+});
\ No newline at end of file