mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-25 08:09:06 -04:00
Don't encode if string is empty in the tag editor (#4012)
This commit is contained in:
1 parent
68f1beaedd
commit
d6ea92e46d
2 files changed
+8
-4
No files matched your search
@@ -300,9 +300,8 @@ describe('encodeEncoding()', () => {
|
||||
it('encodes things', () => {
|
||||
expect(utils.encodeEncoding('hello', 'base64')).toBe('b64::aGVsbG8=::46b');
|
||||
expect(utils.encodeEncoding(null, 'base64')).toBe(null);
|
||||
expect(utils.encodeEncoding('hello', 'unknown')).toBe('hello');
|
||||
expect(utils.encodeEncoding('hello')).toBe('hello');
|
||||
expect(utils.encodeEncoding('hello', 'utf8')).toBe('hello');
|
||||
expect(utils.encodeEncoding('', 'base64')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -314,5 +313,6 @@ describe('decodeEncoding()', () => {
|
||||
expect(utils.decodeEncoding('aGVsbG8=')).toBe('aGVsbG8=');
|
||||
expect(utils.decodeEncoding('hello')).toBe('hello');
|
||||
expect(utils.decodeEncoding(null)).toBe(null);
|
||||
expect(utils.decodeEncoding('')).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -246,11 +246,15 @@ export function getDefaultFill(name: string, args: NunjucksParsedTagArg[]) {
|
||||
return `${name} ${stringArgs.join(', ')}`;
|
||||
}
|
||||
|
||||
export function encodeEncoding(value: string, encoding: 'base64') {
|
||||
export function encodeEncoding<T>(value: T, encoding?: 'base64') {
|
||||
if (typeof value !== 'string') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.length === 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (encoding === 'base64') {
|
||||
const encodedValue = Buffer.from(value, 'utf8').toString('base64');
|
||||
return `b64::${encodedValue}::46b`;
|
||||
@@ -259,7 +263,7 @@ export function encodeEncoding(value: string, encoding: 'base64') {
|
||||
return value;
|
||||
}
|
||||
|
||||
export function decodeEncoding(value: string) {
|
||||
export function decodeEncoding<T>(value: T) {
|
||||
if (typeof value !== 'string') {
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user