From d4552cf176370649d35ce1d7fbb9e6629031045e Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Wed, 12 Oct 2022 16:26:32 -0700 Subject: [PATCH] make the json regex better (#20826) * make the json regex better * comment --- src/sql/workbench/contrib/query/browser/gridPanel.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/contrib/query/browser/gridPanel.ts b/src/sql/workbench/contrib/query/browser/gridPanel.ts index 6070d5f0d9..8bcff02ff8 100644 --- a/src/sql/workbench/contrib/query/browser/gridPanel.ts +++ b/src/sql/workbench/contrib/query/browser/gridPanel.ts @@ -73,7 +73,9 @@ const MIN_GRID_HEIGHT = (MIN_GRID_HEIGHT_ROWS * ROW_HEIGHT) + HEADER_HEIGHT + ES // 2. when user clicks a cell, whether the cell content should be displayed in a new text editor as json. // Based on the requirements, the solution doesn't need to be very accurate, a simple regex is enough since it is more // performant than trying to parse the string to object. -const IsJsonRegex = /({.*?})/g; +// Regex explaination: after removing the trailing whitespaces, the string must start with '[' (to support arrays) +// or '{'. And there must be a '}' to match the '{'. +const IsJsonRegex = /^\s*\[*\s*{.*?}/g; export class GridPanel extends Disposable { private container = document.createElement('div');