From 84418818f8499cc8f882965af6c5bef05a4421e5 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Fri, 8 Feb 2013 19:19:48 +0300 Subject: [PATCH] Percent escaping OUI, serial number, product class in device ID string --- common.coffee | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common.coffee b/common.coffee index e670d59..3c257c9 100644 --- a/common.coffee +++ b/common.coffee @@ -23,11 +23,20 @@ exports.arrayToHash = (arr) -> exports.getDeviceId = (deviceIdStruct) -> + # Percent escaping function. Escapes everything except alphanumerics and underscore + esc = (str) -> + str.replace(/[^A-Za-z0-9_]/g, (chr) -> + buf = new require('buffer').Buffer(chr) + rep = '' + rep += "%#{b.toString(16).toUpperCase()}" for b in buf + return rep + ) + # Guaranteeing globally unique id as defined in TR-069 if deviceIdStruct['ProductClass'] - return "#{deviceIdStruct['OUI']}-#{deviceIdStruct['ProductClass']}-#{deviceIdStruct['SerialNumber']}" + return "#{esc(deviceIdStruct['OUI'])}-#{esc(deviceIdStruct['ProductClass'])}-#{esc(deviceIdStruct['SerialNumber'])}" - return "#{deviceIdStruct['OUI']}-#{deviceIdStruct['SerialNumber']}" + return "#{esc(deviceIdStruct['OUI'])}-#{esc(deviceIdStruct['SerialNumber'])}" exports.extend = (obj, mixin) ->