From eb8d46d380a2005dbec3973d40e1dbc27991fdb7 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 27 Sep 2010 16:00:05 -0700 Subject: Differentiate between flags and empty keys in $location.hashSearch * #foo?key=var&flag&emptyKey= should parse into {key:'val', flag: true, emptyKey: ''} * added docs and spec for parseKeyValue function --- src/Angular.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index 2bd21de4..3e53c755 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -370,13 +370,17 @@ function compile(element, existingScope) { } ///////////////////////////////////////////////// -function parseKeyValue(keyValue) { +/** + * Parses an escaped url query string into key-value pairs. + * @return Object.<(string|boolean)> + */ +function parseKeyValue(/**string*/keyValue) { var obj = {}, key_value, key; foreach((keyValue || "").split('&'), function(keyValue){ if (keyValue) { key_value = keyValue.split('='); key = unescape(key_value[0]); - obj[key] = key_value[1] ? unescape(key_value[1]) : true; + obj[key] = isDefined(key_value[1]) ? unescape(key_value[1]) : true; } }); return obj; -- cgit v1.2.3