Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: d85bd513a6
...
compare: 300c827a36
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 02, 2012
Tim Becker test for <> 0e7c267
Tim Becker rudimentary html escape e92af37
Commits on May 03, 2012
Tim Becker better html handling 300c827
Showing with 44 additions and 8 deletions.
  1. +25 −4 hexy.js
  2. +1 −1  package.json
  3. +18 −3 test.js
View
29 hexy.js
@@ -111,7 +111,6 @@
// In case you discover bugs, spelling errors, offer suggestions for
// improvements or would like to help out with the project, you can contact
// me directly (tim@kuriositaet.de).
-
var hexy = function (buffer, config) {
config = config || {}
var h = new Hexy(buffer, config)
@@ -200,7 +199,9 @@ var Hexy = function (buffer, config) {
str += rpad(hex_formatted, padlen)
if (self.annotate === "ascii") {
str+=" "
- str+=raw.replace(/[\000-\040\177-\377]/g, ".")
+ var ascii = raw.replace(/[\000-\040\177-\377]/g, ".")
+ if (self.html) {str += escape(ascii)}
+ else { str += ascii }
}
if (self.html) {
str += "</div>\n"
@@ -253,12 +254,32 @@ var Hexy = function (buffer, config) {
return s
}
var rpad = function(s, len) {
- while(s.length < len) {
- s += " "
+ for (var n = len - s.length; n!=0; --n) {
+ if (self.html) {
+ s += "&nbsp;"
+ } else {
+ s += " "
+ }
+
}
+// while(s.length < len) {
+// if (self.html) {
+// s += "&nbsp;"
+// } else {
+// s += " "
+// }
+// }
return s
}
+ var escape = function (str) {
+ str = str.split("&").join("&amp;")
+ str = str.split("<").join("&lt;")
+ str = str.split(">").join("&gt;")
+ return str
+ }
+
+
}
/*
var fs = require('fs'),
View
2  package.json
@@ -1,6 +1,6 @@
{
"name" : "hexy",
- "version" : "0.2.2",
+ "version" : "0.2.3",
"description" : "hexdump, binary pretty-printing",
"author" : "Tim Becker <tim.becker@kuriositaet.de>",
"main" : "./hexy.js",
View
21 test.js
@@ -56,7 +56,7 @@ var results = [
"<div class='hexy'>\n"+
"<div class='00000000 even'>00000000: 3031 3233 3435 3637 3839 6162 6364 6566 0123456789abcdef</div>\n"+
"<div class='00000010 odd'>00000010: 6768 696a 6b6c 6d6e 6f70 7172 7374 7576 ghijklmnopqrstuv</div>\n"+
-"<div class='00000020 even'>00000020: 7778 7a79 wxzy</div>\n"+
+"<div class='00000020 even'>00000020: 7778 7a79 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wxzy</div>\n"+
"</div>\n",
]
@@ -104,11 +104,26 @@ _08 = String.fromCharCode(8)
_40 = "@"
_53 = "S"
_5100 = "Q"+_00
-str2 = _00 + _00 + _08 + _40 + _53 + _00 + _0000 + _5100 + _0000 + _5100 + _0000
-xxd2 = "00000000: 0000 0840 5300 0000 5100 0000 5100 0000 ...@S...Q...Q...\n"
+var str2 = _00 + _00 + _08 + _40 + _53 + _00 + _0000 + _5100 + _0000 + _5100 + _0000
+var xxd2 = "00000000: 0000 0840 5300 0000 5100 0000 5100 0000 ...@S...Q...Q...\n"
failed += check(xxd2, hexy.hexy(str2))
++total
+str3 = "#include<stdio.h>\n"
+xxd3 = "00000000: 2369 6e63 6c75 6465 3c73 7464 696f 2e68 #include<stdio.h\n"+
+ "00000010: 3e0a >.\n"
+
+failed += check(xxd3, hexy.hexy(str3))
+++total
+
+xxd4 = "<div class='hexy'>\n"+
+ "<div class='00000000 even'>00000000: 2369 6e63 6c75 6465 3c73 7464 696f 2e68 #include&lt;stdio.h</div>\n"+
+ "<div class='00000010 odd'>00000010: 3e0a &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;.</div>\n"+
+ "</div>\n"
+
+failed += check(xxd4, hexy.hexy(str3, {html:true}))
+++total
+
p("failed: "+failed+" of "+total)

No commit comments for this range

Something went wrong with that request. Please try again.