Skip to content

Commit

Permalink
fix: secret messages right next to each other
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Oct 9, 2024
1 parent 56989d3 commit b147813
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jest.autoMockOff();
import { InvisibleWrapper } from './InvisibleWrapper';
import { MESSAGE_END } from './secret';

const key1 = {
key: 'key1',
Expand All @@ -11,6 +12,11 @@ const key2 = {
translation: 'translation2',
defaultValue: 'defaultValue2',
};
const keyWithMessageEndInside = {
key: `key${MESSAGE_END}3`,
translation: `translation${MESSAGE_END}3`,
defaultValue: `defaultValue${MESSAGE_END}3`,
};

describe('invisible wrapper', () => {
it('wraps and unwraps', () => {
Expand Down Expand Up @@ -67,4 +73,24 @@ describe('invisible wrapper', () => {
expect(unwraped.keys[1].key).toEqual(key1.key);
expect(unwraped.keys[1].defaultValue).toEqual(undefined);
});

it('wraps and unwraps nested keys newlines fully encoded', () => {
// simulating external wrapper
const externalWrapper = InvisibleWrapper({ fullKeyEncode: true });
const wrapper = InvisibleWrapper({ fullKeyEncode: false });

const wrapped = externalWrapper.wrap({
...key1,
translation:
key1.translation + externalWrapper.wrap(keyWithMessageEndInside),
});
const unwraped = wrapper.unwrap(wrapped);
expect(unwraped.text).toEqual(
key1.translation + keyWithMessageEndInside.translation
);
expect(unwraped.keys[0].key).toEqual(keyWithMessageEndInside.key);
expect(unwraped.keys[0].defaultValue).toEqual(undefined);
expect(unwraped.keys[1].key).toEqual(key1.key);
expect(unwraped.keys[1].defaultValue).toEqual(undefined);
});
});
2 changes: 1 addition & 1 deletion packages/web/src/package/observers/invisible/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as FastTextEncoding from 'fast-text-encoding';
// eslint-disable-next-line no-console
console.assert?.(FastTextEncoding);

const MESSAGE_END = '\x03'; // using End of Text (ETX) character to separate messages
export const MESSAGE_END = '\x0A'; // using LF character to separate messages

export const INVISIBLE_CHARACTERS = ['\u200C', '\u200D'];

Expand Down

0 comments on commit b147813

Please sign in to comment.