Skip to content

Commit

Permalink
Fixed escaping special characters (fixes #753).
Browse files Browse the repository at this point in the history
  • Loading branch information
radekmie committed Jul 2, 2020
1 parent 0160799 commit 3db196e
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Next

- **Fixed:** Escaping special characters. [\#753](https://github.com/vazco/uniforms/issues/753)

## [v3.0.0-alpha.5](https://github.com/vazco/uniforms/tree/v3.0.0-alpha.5) (2020-06-17)

- **Breaking:** Removed `modelSync` from `AutoForm` state. [\#739](https://github.com/vazco/uniforms/issues/739)
Expand Down
7 changes: 7 additions & 0 deletions packages/uniforms-antd/__tests__/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,10 @@ test('<RadioField> - renders a wrapper with unknown props', () => {
expect(wrapper.find(Radio.Group).prop('data-y')).toBe('y');
expect(wrapper.find(Radio.Group).prop('data-z')).toBe('z');
});

test('<RadioField> - works with special characters', () => {
mount(
<RadioField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
14 changes: 14 additions & 0 deletions packages/uniforms-antd/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ test('<SelectField> - renders a wrapper with unknown props', () => {
expect(wrapper.find(Select).prop('data-z')).toBe('z');
});

test('<SelectField> - works with special characters', () => {
mount(
<SelectField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});

test('<SelectField checkboxes> - renders a set of checkboxes', () => {
const element = <SelectField checkboxes name="x" />;
const wrapper = mount(
Expand Down Expand Up @@ -473,3 +480,10 @@ test('<SelectField checkboxes> - renders a wrapper with unknown props', () => {
expect(wrapper.find(Radio.Group).prop('data-y')).toBe('y');
expect(wrapper.find(Radio.Group).prop('data-z')).toBe('z');
});

test('<SelectField checkboxes> - works with special characters', () => {
mount(
<SelectField checkboxes name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
7 changes: 7 additions & 0 deletions packages/uniforms-bootstrap3/__tests__/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,10 @@ test('<RadioField> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-y')).toBe('y');
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<RadioField> - works with special characters', () => {
mount(
<RadioField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
14 changes: 14 additions & 0 deletions packages/uniforms-bootstrap3/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ test('<SelectField> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField> - works with special characters', () => {
mount(
<SelectField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});

test('<SelectField checkboxes> - renders a set of checkboxes', () => {
const element = <SelectField checkboxes name="x" />;
const wrapper = mount(
Expand Down Expand Up @@ -491,3 +498,10 @@ test('<SelectField checkboxes> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-y')).toBe('y');
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField checkboxes> - works with special characters', () => {
mount(
<SelectField checkboxes name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap3/src/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

export type RadioFieldProps = Override<
HTMLProps<HTMLDivElement>,
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap3/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

const xor = (item, array) => {
const index = array.indexOf(item);
Expand Down
7 changes: 7 additions & 0 deletions packages/uniforms-bootstrap4/__tests__/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,10 @@ test('<RadioField> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-y')).toBe('y');
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<RadioField> - works with special characters', () => {
mount(
<RadioField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
14 changes: 14 additions & 0 deletions packages/uniforms-bootstrap4/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ test('<SelectField> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField> - works with special characters', () => {
mount(
<SelectField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});

test('<SelectField checkboxes> - renders a set of checkboxes', () => {
const element = <SelectField checkboxes name="x" />;
const wrapper = mount(
Expand Down Expand Up @@ -491,3 +498,10 @@ test('<SelectField checkboxes> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-y')).toBe('y');
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField checkboxes> - works with special characters', () => {
mount(
<SelectField checkboxes name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap4/src/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

export type RadioFieldProps = Override<
HTMLProps<HTMLDivElement>,
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap4/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

const xor = (item, array) => {
const index = array.indexOf(item);
Expand Down
7 changes: 7 additions & 0 deletions packages/uniforms-material/__tests__/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,10 @@ test('<RadioField> - renders a TextField with correct error text (specified)', (

expect(wrapper.find(FormHelperText).text()).toBe('Error');
});

test('<RadioField> - works with special characters', () => {
mount(
<RadioField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
14 changes: 14 additions & 0 deletions packages/uniforms-material/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ test('<SelectField> - renders a SelectField with correct error text (showInlineE
expect(wrapper.find(FormHelperText)).toHaveLength(0);
});

test('<SelectField> - works with special characters', () => {
mount(
<SelectField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});

test('<SelectField checkboxes> - renders a set of Radio buttons', () => {
// @ts-ignore Fix SelectFieldProps.
const element = <SelectField checkboxes name="x" />;
Expand Down Expand Up @@ -616,3 +623,10 @@ test('<SelectField checkboxes> - renders Switch with appearance=switch', () => {
expect(wrapper.find(Checkbox)).toHaveLength(0);
expect(wrapper.find(Switch)).toHaveLength(2);
});

test('<SelectField checkboxes> - works with special characters', () => {
mount(
<SelectField checkboxes name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
2 changes: 1 addition & 1 deletion packages/uniforms-material/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

const xor = (item, array) => {
const index = array.indexOf(item);
Expand Down
7 changes: 7 additions & 0 deletions packages/uniforms-semantic/__tests__/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,10 @@ test('<RadioField> - renders correct error text (showInlineError=false)', () =>

expect(wrapper.find('.ui.red.label').length).toBe(0);
});

test('<RadioField> - works with special characters', () => {
mount(
<RadioField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
14 changes: 14 additions & 0 deletions packages/uniforms-semantic/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ test('<SelectField> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField> - works with special characters', () => {
mount(
<SelectField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});

test('<SelectField checkboxes> - renders a set of checkboxes', () => {
const element = <SelectField checkboxes name="x" />;
const wrapper = mount(
Expand Down Expand Up @@ -481,6 +488,13 @@ test('<SelectField checkboxes> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField checkboxes> - works with special characters', () => {
mount(
<SelectField checkboxes name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});

test('<SelectField> - renders correct error text (specified)', () => {
const error = new Error();
const element = (
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-semantic/src/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

export type RadioFieldProps = Override<
HTMLProps<HTMLDivElement>,
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-semantic/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

const xor = (item, array) => {
const index = array.indexOf(item);
Expand Down
7 changes: 7 additions & 0 deletions packages/uniforms-unstyled/__tests__/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,10 @@ test('<RadioField> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-y')).toBe('y');
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<RadioField> - works with special characters', () => {
mount(
<RadioField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
14 changes: 14 additions & 0 deletions packages/uniforms-unstyled/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ test('<SelectField> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField> - works with special characters', () => {
mount(
<SelectField name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});

test('<SelectField checkboxes> - renders a set of checkboxes', () => {
const element = <SelectField checkboxes name="x" />;
const wrapper = mount(
Expand Down Expand Up @@ -480,3 +487,10 @@ test('<SelectField checkboxes> - renders a wrapper with unknown props', () => {
expect(wrapper.find('div').at(0).prop('data-y')).toBe('y');
expect(wrapper.find('div').at(0).prop('data-z')).toBe('z');
});

test('<SelectField checkboxes> - works with special characters', () => {
mount(
<SelectField checkboxes name="x" />,
createContext({ x: { type: String, allowedValues: ['ă', 'ș'] } }),
);
});
2 changes: 1 addition & 1 deletion packages/uniforms-unstyled/src/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const base64 =
typeof btoa !== 'undefined'
? btoa
: (x: string) => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

export type RadioFieldProps = Override<
HTMLProps<HTMLDivElement>,
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms-unstyled/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connectField, filterDOMProps, Override } from 'uniforms';

const base64: typeof btoa =
typeof btoa !== 'undefined' ? btoa : x => Buffer.from(x).toString('base64');
const escape = (x: string) => base64(x).replace(/=+$/, '');
const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');

export type SelectFieldProps = Override<
HTMLProps<HTMLDivElement>,
Expand Down

0 comments on commit 3db196e

Please sign in to comment.