Skip to content

Commit 906d0cd

Browse files
authored
Bugfix/fix mask values (#89)
* Compare key names case-insensitively. * Loop all key-value-pairs from the collection that match the key. * The variable names may be longer, but readability is now improved. * Changed the behavior for boolean/flag-attributes: They are no longer considered as values but as keys, which means that they are not changed in the output.
1 parent c5f77e9 commit 906d0cd

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

src/filters.js

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ SAMLTraceIO_filters.obfuscateValueFilter = function(collection, key) {
8989
* i.e.
9090
* myfilter = SAMLTraceIO_filters.overwriteCookieValueFilter(
9191
* 'requestHeaders', 'Cookie', '{overwritten}');
92-
* will return a function that can called with a SAMLTrace.Request instance
92+
* will return a function that can be called with a SAMLTrace.Request instance
9393
* as argument, and will filter based on provided parameters,
9494
* i.e.
9595
* filtered_request = myfilter(unfiltered_request);
@@ -109,33 +109,40 @@ SAMLTraceIO_filters.genMultiValueFilter = function(collection, key, separator, n
109109
return;
110110
}
111111

112-
let elem = req[collection].find(item => item.name === key);
113-
if (elem == null) {
112+
const elems = req[collection].filter(item => item.name.toUpperCase() === key.toUpperCase());
113+
if (elems == null || elems.length === 0) {
114114
return;
115115
}
116-
117-
var ac = elem.value.split(separator);
118-
var fc = [];
119-
120-
for (let i = 0; i < ac.length; i++) {
121-
var kk,kv;
122-
if (ac[i].indexOf('=')>=0) {
123-
kk=ac[i].split('=')[0];
124-
kv=ac[i].split('=')[1];
125-
} else {
126-
kk='';// no key
127-
kv=ac[i];
128-
}
129-
130-
new_val_func(kk, kv, (kkk, newval) => {
131-
// create syntactically correct entry:
132-
fc.push([kkk, newval].join('='));
133116

134-
// update element's value on the last iteration
135-
if (i === ac.length - 1) {
136-
elem.value = fc.join(separator);
117+
for (let index = 0; index < elems.length; index++) {
118+
let elem = elems[index];
119+
let originalKeyValuePairs = elem.value.split(separator);
120+
let processedKeyValuePairs = [];
121+
122+
for (let i = 0; i < originalKeyValuePairs.length; i++) {
123+
let subkey, subvalue;
124+
if (originalKeyValuePairs[i].indexOf('=') >= 0) {
125+
subkey = originalKeyValuePairs[i].split('=')[0];
126+
subvalue = originalKeyValuePairs[i].split('=')[1];
127+
} else {
128+
subkey = originalKeyValuePairs[i];
129+
subvalue = null; // no value for boolean/flag-attributes
137130
}
138-
});
131+
132+
new_val_func(subkey, subvalue, (processedSubkey, newval) => {
133+
// create syntactically correct entry:
134+
if (subvalue !== null) {
135+
processedKeyValuePairs.push([processedSubkey, newval].join('='));
136+
} else {
137+
processedKeyValuePairs.push(processedSubkey);
138+
}
139+
140+
// update element's value on the last iteration
141+
if (i === originalKeyValuePairs.length - 1) {
142+
elem.value = processedKeyValuePairs.join(separator);
143+
}
144+
});
145+
}
139146
}
140147
};
141148
}

0 commit comments

Comments
 (0)