mirror of https://github.com/status-im/consul.git
ui: Ensure any colons in headers aren't split out (#8293)
This commit is contained in:
parent
e72af87918
commit
4b51eb6f8e
|
@ -1,9 +1,9 @@
|
||||||
export default function() {
|
export default function() {
|
||||||
return function(lines) {
|
return function(lines) {
|
||||||
return lines.reduce(function(prev, item) {
|
return lines.reduce(function(prev, item) {
|
||||||
const temp = item.split(':');
|
const [key, ...value] = item.split(':');
|
||||||
if (temp.length > 1) {
|
if (value.length > 0) {
|
||||||
prev[temp[0].trim()] = temp[1].trim();
|
prev[key.trim()] = value.join(':').trim();
|
||||||
}
|
}
|
||||||
return prev;
|
return prev;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
|
@ -15,4 +15,16 @@ module('Unit | Utility | http/create-headers', function() {
|
||||||
const actual = parseHeaders(lines);
|
const actual = parseHeaders(lines);
|
||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
test('it parses header values with colons correctly', function(assert) {
|
||||||
|
const expected = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Consul-Index': '1:2:3',
|
||||||
|
};
|
||||||
|
const lines = `
|
||||||
|
Content-Type: application/json
|
||||||
|
X-Consul-Index: 1:2:3
|
||||||
|
`.split('\n');
|
||||||
|
const actual = parseHeaders(lines);
|
||||||
|
assert.deepEqual(actual, expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue