-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspace]Fix page crash caused by invalid workspace color (#7671)
* Add validation for workspace color Signed-off-by: Lin Wang <[email protected]> * Changeset file for PR #7671 created/updated --------- Signed-off-by: Lin Wang <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit 248c8ff) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f2f363a
commit efa37ef
Showing
10 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- [Workspace]Fix page crash caused by invalid workspace color ([#7671](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7671)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { validateWorkspaceColor } from '../utils'; | ||
|
||
describe('validateWorkspaceColor', () => { | ||
it('should return true for a valid 6-digit hex color code', () => { | ||
expect(validateWorkspaceColor('#ABCDEF')).toBe(true); | ||
expect(validateWorkspaceColor('#123456')).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid 3-digit hex color code', () => { | ||
expect(validateWorkspaceColor('#ABC')).toBe(true); | ||
expect(validateWorkspaceColor('#DEF')).toBe(true); | ||
}); | ||
|
||
it('should return false for an invalid color code', () => { | ||
expect(validateWorkspaceColor('#GHI')).toBe(false); | ||
expect(validateWorkspaceColor('#12345')).toBe(false); | ||
expect(validateWorkspaceColor('#ABCDEFG')).toBe(false); | ||
expect(validateWorkspaceColor('ABCDEF')).toBe(false); | ||
}); | ||
|
||
it('should return false for an empty string', () => { | ||
expect(validateWorkspaceColor('')).toBe(false); | ||
}); | ||
|
||
it('should return false for undefined', () => { | ||
expect(validateWorkspaceColor()).toBe(false); | ||
}); | ||
|
||
it('should be case-insensitive', () => { | ||
expect(validateWorkspaceColor('#abcdef')).toBe(true); | ||
expect(validateWorkspaceColor('#ABC')).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// Reference https://github.com/opensearch-project/oui/blob/main/src/services/color/is_valid_hex.ts | ||
export const validateWorkspaceColor = (color?: string) => | ||
!!color && /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters