Merge pull request #332 from Jigsaw-Code/trevj-strip-whitespace

strip whitespace from server configs, like we used to
This commit is contained in:
trevj 2018-12-03 17:04:50 -05:00 • committed by GitHub
commit 9507d2f8ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -46,4 +46,18 @@ describe('parseManualServerConfig', () => {
expect(result.apiUrl).toEqual('http://abc.com/xyz');
expect(result.certSha256).toEqual('1234567');
});
it('strips whitespace', () => {
const result =
parseManualServerConfig('{"apiUrl":http://abc.com/xyz, "certSha256":"123 4567"}');
expect(result.apiUrl).toEqual('http://abc.com/xyz');
expect(result.certSha256).toEqual('1234567');
});
it('strips newlines', () => {
const result =
parseManualServerConfig('{"apiUrl":http://abc.com/xyz, "certSha256":"123\n4567"}');
expect(result.apiUrl).toEqual('http://abc.com/xyz');
expect(result.certSha256).toEqual('1234567');
});
});

View file

@ -30,6 +30,9 @@ export function parseManualServerConfig(userInput: string): ManualServerConfig {
userInput = userInput.substring(0, indexOfLastBrace + 1);
}
// Strip whitespace.
userInput = userInput.replace(/\s+/g, '');
const config = jsonic(userInput) as ManualServerConfig;
if (!config.apiUrl) {