From 1aed17374f3340bff8f1528af14f4e5453261bb9 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Sun, 28 Jul 2013 14:33:59 +0300 Subject: [PATCH] Fixed bug in parsing authentication challange header --- auth.coffee | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/auth.coffee b/auth.coffee index 152d0e0..135edef 100644 --- a/auth.coffee +++ b/auth.coffee @@ -5,11 +5,15 @@ exports.parseAuthHeader = (authHeader) -> res = {} i = authHeader.indexOf(' ') res['method'] = authHeader.slice(0, i) - options = authHeader.slice(i + 1).split(/\s*,\s*/) - - for o in options - v = o.split('=') - res[v[0]] = v[1].slice(1, -1) + + options = authHeader.slice(i + 1) + regex = /([a-z]+)="([a-zA-Z0-9\/\.@\-,]+)"/g + while (r = regex.exec(options)) != null + res[r[1]] = r[2] + + regex = /([a-z]+)=([a-zA-Z0-9\/\.@\-]+)/g + while (r = regex.exec(options)) != null + res[r[1]] = r[2] return res @@ -41,8 +45,8 @@ exports.digest = (username, password, uri, httpMethod, body, authHeader) -> response = crypto.createHash('md5') response.update(ha1).update(':').update(authHeader.nonce) - if authHeader.qop? - response.update(':').update(nc).update(':').update(cnonce).update(':').update(authHeader.qop) + if qop? + response.update(':').update(nc).update(':').update(cnonce).update(':').update(qop) response.update(':').update(ha2) response = response.digest('hex')