-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(getJsonResource and scrubControlChars): add getJsonResource and …
…scrubControlChars AFFECTS PACKAGES: @esri/arcgis-rest-portal
- Loading branch information
1 parent
27f162f
commit 6bb9215
Showing
5 changed files
with
105 additions
and
1 deletion.
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
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
12 changes: 12 additions & 0 deletions
12
packages/arcgis-rest-portal/src/util/scrub-control-chars.ts
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,12 @@ | ||
const CONTROL_CHAR_MATCHER = /[\x00-\x1F\x7F-\x9F\xA0]/g; | ||
|
||
/** | ||
* Returns a string with all control characters removed. | ||
* | ||
* Doesn't remove characters | ||
* | ||
* @param str - the string to scrub | ||
*/ | ||
export function scrubControlChars (str: string) { | ||
return str.replace(CONTROL_CHAR_MATCHER, ""); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
packages/arcgis-rest-portal/test/util/scrub-control-chars.test.ts
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,22 @@ | ||
import { scrubControlChars } from "../../src/util/scrub-control-chars"; | ||
|
||
describe('scrubControlChars', function () { | ||
it('removes control characters', function () { | ||
let hasAllControlChars = 'foo'; | ||
// C0 | ||
for (let i = 0; i < 32; i++) { | ||
hasAllControlChars += String.fromCharCode(i); | ||
} | ||
hasAllControlChars += 'bar'; | ||
// C1 | ||
for (let i = 128; i < 159; i++) { | ||
hasAllControlChars += String.fromCharCode(i); | ||
} | ||
hasAllControlChars += 'baz'; | ||
|
||
// ISO 8859 special char | ||
hasAllControlChars += String.fromCharCode(160); | ||
|
||
expect(scrubControlChars(hasAllControlChars)).toBe('foobarbaz', "removes all control chars") | ||
}); | ||
}); |