Skip to content

Commit

Permalink
Fix config parsing where undefined values were kept
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Mar 20, 2024
1 parent 6a27454 commit 7ebaaa2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ function expandModuleConfig(config: Record<string, unknown> | undefined) {
);
}

function omitUndefinedValuesFromOptions(obj: Options) {
return Object.fromEntries(
Object.entries(obj).filter((entry) => entry[1] !== undefined),
);
}

function expandConfig(
containerOrSelector: HTMLElement | string,
options: Options,
Expand Down Expand Up @@ -785,7 +791,11 @@ function expandConfig(
};
}

const config = { ...quillDefaults, ...themeDefaults, ...options };
const config = {
...quillDefaults,
...omitUndefinedValuesFromOptions(themeDefaults),
...omitUndefinedValuesFromOptions(options),
};

let registry = options.registry;
if (registry) {
Expand Down
16 changes: 16 additions & 0 deletions packages/quill/test/unit/core/quill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,13 @@ describe('Quill', () => {
expect(config.registry).toBe(globalRegistry);
});

test('registry with undefined values', () => {
const config = expandConfig(`#${testContainerId}`, {
registry: undefined,
});
expect(config.registry).toBe(globalRegistry);
});

describe('formats', () => {
test('null value allows all formats', () => {
const config = expandConfig(`#${testContainerId}`, {
Expand All @@ -800,6 +807,15 @@ describe('Quill', () => {
expect(config.registry.query('bold')).toBeTruthy();
});

test('undefined value allows all formats', () => {
const config = expandConfig(`#${testContainerId}`, {
formats: undefined,
});

expect(config.registry.query('cursor')).toBeTruthy();
expect(config.registry.query('bold')).toBeTruthy();
});

test('always allows core formats', () => {
const config = expandConfig(`#${testContainerId}`, {
formats: ['bold'],
Expand Down

0 comments on commit 7ebaaa2

Please sign in to comment.