From 9afd29f19695188cf37292a365986eb5de6f5cbc Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Wed, 27 Nov 2024 16:07:21 -0300 Subject: [PATCH] Fix issue with invalid characters in SplitSDKMachineName header --- CHANGES.txt | 3 +++ src/services/__tests__/decorateHeaders.spec.ts | 9 ++++++++- src/services/decorateHeaders.ts | 5 +++++ src/services/splitHttpClient.ts | 4 ++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4a335cf8..84820147 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +2.0.2 (XXX XX, 2024) + - Bugfixing - Sanitize the `SplitSDKMachineName` header value to avoid exceptions on HTTP/S requests when it contains non ISO-8859-1 characters (Related to issue https://github.com/splitio/javascript-client/issues/847). + 2.0.1 (November 25, 2024) - Bugfixing - Fixed an issue with the SDK_UPDATE event on server-side, where it was not being emitted if there was an empty segment and the SDK received a feature flag update notification. diff --git a/src/services/__tests__/decorateHeaders.spec.ts b/src/services/__tests__/decorateHeaders.spec.ts index c50d6620..e6cfb481 100644 --- a/src/services/__tests__/decorateHeaders.spec.ts +++ b/src/services/__tests__/decorateHeaders.spec.ts @@ -1,5 +1,5 @@ import { ISettings } from '../../types'; -import { decorateHeaders } from '../decorateHeaders'; +import { decorateHeaders, removeNonISO88591 } from '../decorateHeaders'; const HEADERS = { Authorization: 'Bearer SDK-KEY', @@ -48,3 +48,10 @@ describe('decorateHeaders', () => { expect(settings.log.error).toHaveBeenCalledWith('Problem adding custom headers to request decorator: Error: Unexpected error'); }); }); + +test('removeNonISO88591', () => { + expect(removeNonISO88591('')).toBe(''); + expect(removeNonISO88591('This is a test')).toBe('This is a test'); + expect(removeNonISO88591('This is a test ó \u0FFF 你')).toBe('This is a test ó '); + expect(removeNonISO88591('Emiliano’s-MacBook-Pro')).toBe('Emilianos-MacBook-Pro'); +}); diff --git a/src/services/decorateHeaders.ts b/src/services/decorateHeaders.ts index 4a95219f..1a4dac05 100644 --- a/src/services/decorateHeaders.ts +++ b/src/services/decorateHeaders.ts @@ -30,3 +30,8 @@ export function decorateHeaders(settings: ISettings, headers: Record void = () => { }, logErrorsAsInfo: boolean = false): Promise {