Skip to content

Commit

Permalink
fix: escape quotes in title generated fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lsh committed Jul 19, 2023
1 parent d535812 commit b1d0023
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions site/_data/versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vega: 5.25.0
vega-lite: 5.9.3
vega-embed: 6.22.1
vega-tooltip: 0.32.0
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, '\\"');

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

0 comments on commit b1d0023

Please sign in to comment.