Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Escape Quotes in tooltip title #9019

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compile/mark/encode/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function tooltipData(
};

const title = fieldDef.title || defaultTitle(fieldDef, formatConfig);
const key = array(title).join(', ');
const key = array(title).join(', ').replaceAll(/"/g, '\\"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, do we not have a utility method for this already? Does this problem not happen for other texts, axis labels or titles?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see one, but maybe I didn't look in the right place. I'm not sure the other areas have the same problem since this one specifically generates a dictionary rather than acts as a value.


let value: string;

Expand Down
13 changes: 13 additions & 0 deletions test/compile/mark/encode/tooltip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ describe('compile/mark/encode/tooltip', () => {
signal: '{"baz": isValid(datum["Foobar"]) ? datum["Foobar"] : ""+datum["Foobar"]}'
});
});

it('generates correct keys and values for channels with title with quotes', () => {
const model = parseUnitModelWithScaleAndLayoutSize({
mark: {type: 'point', tooltip: true},
encoding: {
color: {field: 'Foobar', type: 'nominal', title: '"baz"'}
}
});
const props = tooltip(model);
expect(props.tooltip).toEqual({
signal: '{"\\"baz\\"": isValid(datum["Foobar"]) ? datum["Foobar"] : ""+datum["Foobar"]}'
});
});
});

describe('tooltipForEncoding', () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"resolveJsonModule": true,
"suppressImplicitAnyIndexErrors": true,
"isolatedModules": true,
"lib": ["ESNext.Array", "DOM", "DOM.Iterable"],
"lib": ["ESNext.Array", "DOM", "DOM.Iterable", "ES2021.String"],
"noEmit": true
},
"files": ["src/index.ts"],
Expand Down