From de45423289f3f559f945c8d578120fef70efd1f2 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 1 Nov 2017 21:24:33 +0100 Subject: [PATCH] bugfix JSON.parse error blockDevices() --- CHANGELOG.md | 2 ++ lib/filesystem.js | 1 + lib/util.js | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90d235e..45b6156 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,8 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.32.2 | 2017-10-23 | bugfix JSON.parse error `blockDevices()` | +| 3.32.1 | 2017-10-23 | updated docs | | 3.32.0 | 2017-10-23 | extended `memLayout()` - added manufacturer | | 3.31.4 | 2017-10-21 | updated `README.md` | | 3.31.3 | 2017-10-21 | bugfix `graphics()`, fixed typo `README.md` | diff --git a/lib/filesystem.js b/lib/filesystem.js index 7b950ac..fc2d25c 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -151,6 +151,7 @@ function parseBlk(lines) { let data = []; lines.filter(line => line !== '').forEach((line) => { + line = util.decodeEscapeSequence(line); line = line.replace(/\\/g,'\\\\'); let disk = JSON.parse(line); data.push({ diff --git a/lib/util.js b/lib/util.js index fa8f450..3d32b61 100644 --- a/lib/util.js +++ b/lib/util.js @@ -79,8 +79,16 @@ function getValue(lines, property, separator, trimmed) { return ''; } +function decodeEscapeSequence(str, base) { + base = base || 16 + return str.replace(/\\x([0-9A-Fa-f]{2})/g, function() { + return String.fromCharCode(parseInt(arguments[1], base)); + }); +}; + exports.isFunction = isFunction; exports.unique = unique; exports.sortByKey= sortByKey; exports.cores = cores; exports.getValue = getValue; +exports.decodeEscapeSequence = decodeEscapeSequence;