ui: Ensure any colons in headers aren't split out (#8293)

This commit is contained in:
John Cowen 2020-07-13 14:22:15 +01:00 committed by GitHub
parent e72af87918
commit 4b51eb6f8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -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;
}, {}); }, {});

View File

@ -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);
});
}); });