aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPete Bacon Darwin2013-06-20 13:59:46 +0100
committerPete Bacon Darwin2013-06-20 14:13:16 +0100
commit8264d08085adc2ab57f6598b9fc9f6e263c8b4f3 (patch)
tree647bc3cf34d7ac98808518f4f98dc7175306c733 /src
parenta7908134cb22c8c1efb21f780d4a6efdfde2b78c (diff)
downloadangular.js-8264d08085adc2ab57f6598b9fc9f6e263c8b4f3.tar.bz2
fix(Angular.js): don't crash on invalid query parameters
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 50d7d76c..839a5a77 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -822,16 +822,35 @@ function startingTag(element) {
/////////////////////////////////////////////////
/**
+ * Tries to decode the URI component without throwing an exception.
+ *
+ * @private
+ * @param str value potential URI component to check.
+ * @returns {boolean} True if `value` can be decoded
+ * with the decodeURIComponent function.
+ */
+function tryDecodeURIComponent(value) {
+ try {
+ return decodeURIComponent(value);
+ } catch(e) {
+ // Ignore any invalid uri component
+ }
+}
+
+
+/**
* Parses an escaped url query string into key-value pairs.
* @returns Object.<(string|boolean)>
*/
function parseKeyValue(/**string*/keyValue) {
var obj = {}, key_value, key;
forEach((keyValue || "").split('&'), function(keyValue){
- if (keyValue) {
+ if ( keyValue ) {
key_value = keyValue.split('=');
- key = decodeURIComponent(key_value[0]);
- obj[key] = isDefined(key_value[1]) ? decodeURIComponent(key_value[1]) : true;
+ key = tryDecodeURIComponent(key_value[0]);
+ if ( isDefined(key) ) {
+ obj[key] = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
+ }
}
});
return obj;