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

[osd/std] Add additional recovery from false-positives in handling of long numerals #5956

Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG] Remove duplicate sample data as id 90943e30-9a47-11e8-b64d-95841ca0b247 ([5668](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5668))
- [BUG][Multiple Datasource] Fix datasource testing connection unexpectedly passed with wrong endpoint [#5663](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5663)
- [Table Visualization] Fix filter action buttons for split table aggregations ([#5619](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5619))
- [osd/std] Add additional recovery from false-positives in handling of long numerals ([#5956](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5956))
- [BUG][Discover] Allow saved sort from search embeddable to load in Dashboard ([#5934](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5934))
- [BUG][Multiple Datasource] Fix missing customApiRegistryPromise param for test connection ([#5944](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5944))


### 🚞 Infrastructure

- Re-enable CI workflows for feature branches ([#2908](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2908))
Expand Down
32 changes: 27 additions & 5 deletions packages/osd-std/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,38 @@
} catch (e) {
hadException = true;
/* There are two types of exception objects that can be raised:
* 1) a proper object with lineNumber and columnNumber which we can use
* 2) a textual message with the position that we need to parse
* 1) a textual message with the position that we need to parse
* i. Unexpected [token|string ...] at position ...
* ii. expected ',' or '}' after property value in object at line ... column ...
* 2) a proper object with lineNumber and columnNumber which we can use
* Note: this might refer to the part of the code that threw the exception but
* we will try it anyway; the regex is specific enough to not produce
* false-positives.
*/
let { lineNumber, columnNumber } = e;
if (!lineNumber || !columnNumber) {
const match = e?.message?.match?.(/^Unexpected token.*at position (\d+)$/);

if (typeof e?.message === 'string') {
/* Check for 1-i (seen in Node)
* Finding "..."෴1111"..." inside a string value, the extra quotes throw a syntax error
* and the position points to " that is assumed to be the begining of a value.
*/
let match = e.message.match(/^Unexpected .*at position (\d+)(\s|$)/);
if (match) {
lineNumber = 1;
// The position is zero-indexed; adding 1 to normalize it for the -2 that comes later
// Add 1 to reach the marker
columnNumber = parseInt(match[1], 10) + 1;
} else {
/* Check for 1-ii (seen in browsers)
* Finding "...,"෴1111"..." inside a string value, the extra quotes throw a syntax error
* and the column number points to the marker after the " that is assumed to be terminating the
* value.
*/
// ToDo: Add functional tests for this path
match = e.message.match(/expected .*at line (\d+) column (\d+)(\s|$)/);

Check warning on line 180 in packages/osd-std/src/json.ts

View check run for this annotation

Codecov / codecov/patch

packages/osd-std/src/json.ts#L180

Added line #L180 was not covered by tests
if (match) {
lineNumber = parseInt(match[1], 10);
columnNumber = parseInt(match[2], 10);

Check warning on line 183 in packages/osd-std/src/json.ts

View check run for this annotation

Codecov / codecov/patch

packages/osd-std/src/json.ts#L182-L183

Added lines #L182 - L183 were not covered by tests
}
}
}

Expand Down
Loading