Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
May 02, 2012
Tim Becker test for <> 0e7c267
Tim Becker rudimentary html escape e92af37
May 03, 2012
Tim Becker better html handling 300c827

Showing 3 changed files with 44 additions and 8 deletions. Show diff stats Hide diff stats

  1. +25 4 hexy.js
  2. +1 1  package.json
  3. +18 3 test.js
29 hexy.js
@@ -111,7 +111,6 @@
111 111 // In case you discover bugs, spelling errors, offer suggestions for
112 112 // improvements or would like to help out with the project, you can contact
113 113 // me directly (tim@kuriositaet.de).
114   -
115 114 var hexy = function (buffer, config) {
116 115 config = config || {}
117 116 var h = new Hexy(buffer, config)
@@ -200,7 +199,9 @@ var Hexy = function (buffer, config) {
200 199 str += rpad(hex_formatted, padlen)
201 200 if (self.annotate === "ascii") {
202 201 str+=" "
203   - str+=raw.replace(/[\000-\040\177-\377]/g, ".")
  202 + var ascii = raw.replace(/[\000-\040\177-\377]/g, ".")
  203 + if (self.html) {str += escape(ascii)}
  204 + else { str += ascii }
204 205 }
205 206 if (self.html) {
206 207 str += "</div>\n"
@@ -253,12 +254,32 @@ var Hexy = function (buffer, config) {
253 254 return s
254 255 }
255 256 var rpad = function(s, len) {
256   - while(s.length < len) {
257   - s += " "
  257 + for (var n = len - s.length; n!=0; --n) {
  258 + if (self.html) {
  259 + s += "&nbsp;"
  260 + } else {
  261 + s += " "
  262 + }
  263 +
258 264 }
  265 +// while(s.length < len) {
  266 +// if (self.html) {
  267 +// s += "&nbsp;"
  268 +// } else {
  269 +// s += " "
  270 +// }
  271 +// }
259 272 return s
260 273 }
261 274
  275 + var escape = function (str) {
  276 + str = str.split("&").join("&amp;")
  277 + str = str.split("<").join("&lt;")
  278 + str = str.split(">").join("&gt;")
  279 + return str
  280 + }
  281 +
  282 +
262 283 }
263 284 /*
264 285 var fs = require('fs'),
2  package.json
... ... @@ -1,6 +1,6 @@
1 1 {
2 2 "name" : "hexy",
3   - "version" : "0.2.2",
  3 + "version" : "0.2.3",
4 4 "description" : "hexdump, binary pretty-printing",
5 5 "author" : "Tim Becker <tim.becker@kuriositaet.de>",
6 6 "main" : "./hexy.js",
21 test.js
@@ -56,7 +56,7 @@ var results = [
56 56 "<div class='hexy'>\n"+
57 57 "<div class='00000000 even'>00000000: 3031 3233 3435 3637 3839 6162 6364 6566 0123456789abcdef</div>\n"+
58 58 "<div class='00000010 odd'>00000010: 6768 696a 6b6c 6d6e 6f70 7172 7374 7576 ghijklmnopqrstuv</div>\n"+
59   -"<div class='00000020 even'>00000020: 7778 7a79 wxzy</div>\n"+
  59 +"<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"+
60 60 "</div>\n",
61 61 ]
62 62
@@ -104,11 +104,26 @@ _08 = String.fromCharCode(8)
104 104 _40 = "@"
105 105 _53 = "S"
106 106 _5100 = "Q"+_00
107   -str2 = _00 + _00 + _08 + _40 + _53 + _00 + _0000 + _5100 + _0000 + _5100 + _0000
108   -xxd2 = "00000000: 0000 0840 5300 0000 5100 0000 5100 0000 ...@S...Q...Q...\n"
  107 +var str2 = _00 + _00 + _08 + _40 + _53 + _00 + _0000 + _5100 + _0000 + _5100 + _0000
  108 +var xxd2 = "00000000: 0000 0840 5300 0000 5100 0000 5100 0000 ...@S...Q...Q...\n"
109 109
110 110 failed += check(xxd2, hexy.hexy(str2))
111 111 ++total
112 112
113 113
  114 +str3 = "#include<stdio.h>\n"
  115 +xxd3 = "00000000: 2369 6e63 6c75 6465 3c73 7464 696f 2e68 #include<stdio.h\n"+
  116 + "00000010: 3e0a >.\n"
  117 +
  118 +failed += check(xxd3, hexy.hexy(str3))
  119 +++total
  120 +
  121 +xxd4 = "<div class='hexy'>\n"+
  122 + "<div class='00000000 even'>00000000: 2369 6e63 6c75 6465 3c73 7464 696f 2e68 #include&lt;stdio.h</div>\n"+
  123 + "<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"+
  124 + "</div>\n"
  125 +
  126 +failed += check(xxd4, hexy.hexy(str3, {html:true}))
  127 +++total
  128 +
114 129 p("failed: "+failed+" of "+total)

No commit comments for this range

Something went wrong with that request. Please try again.