Skip to content

Commit

Permalink
Properly escape grid color values
Browse files Browse the repository at this point in the history
Color definitions with a # need to be escaped to be properly rendered
when used in a background image url
  • Loading branch information
martin-fleck-at authored and tortmayr committed Jun 15, 2024
1 parent 998b9d5 commit 711f72f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/views/ggraph-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class GGraphView extends SGraphView {
}

protected getBackgroundImage(viewport: Readonly<SGraphImpl>, context: RenderingContext, gridManager: GridManager): string {
const color = getComputedStyle(document.documentElement).getPropertyValue(GridProperty.GRID_COLOR).trim();
const color = getComputedStyle(document.documentElement).getPropertyValue(GridProperty.GRID_COLOR).trim().replace(/#/g, '%23');
// eslint-disable-next-line max-len
return `url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${gridManager.grid.x} ${gridManager.grid.y}"><rect width="${gridManager.grid.x}" height="${gridManager.grid.y}" x="0" y="0" fill="none" stroke="${color}" stroke-width="1" /></svg>')`;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/views/glsp-projection-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class GLSPProjectionView extends ProjectedViewportView {
}

protected getBackgroundImage(viewport: Readonly<SGraphImpl>, context: RenderingContext, gridManager: GridManager): string {
const color = getComputedStyle(document.documentElement).getPropertyValue(GridProperty.GRID_COLOR).trim();
const color = getComputedStyle(document.documentElement).getPropertyValue(GridProperty.GRID_COLOR).trim().replace(/#/g, '%23');
// eslint-disable-next-line max-len
return `url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${gridManager.grid.x} ${gridManager.grid.y}"><rect width="${gridManager.grid.x}" height="${gridManager.grid.y}" x="0" y="0" fill="none" stroke="${color}" stroke-width="1" /></svg>')`;
}
Expand Down

0 comments on commit 711f72f

Please sign in to comment.