Skip to content

Commit

Permalink
increasing readability and using .some
Browse files Browse the repository at this point in the history
Signed-off-by: Amber Torrise <[email protected]>
  • Loading branch information
Amber Torrise committed Oct 19, 2023
1 parent 8aacd85 commit 1ae9a6f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/cli/download/data-set/DataSet.Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ImperativeError } from "@zowe/imperative";

function isValidFileName(fileName: string) {
//to prevent magic number eslint errors
//(valid characters deduced from https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
const iso8859_1_start_first = 32; // first valid code point for first chunk of valid characters in the ISO/IEC 8859-1 table
const iso8859_1_end_first = 127;
const iso8859_1_start_second = 160; //second chunk of valid characters
Expand All @@ -32,11 +33,17 @@ function isValidFileName(fileName: string) {
// Extract the decimal representation from the code point (e.g., ☻ = U+263B => 9787)
const decimalRepresentation = parseInt(codePoint.substring(binary), hexadecimal);

// Check if the code point is in the range of valid characters (valid numbers deduced from https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
if ((decimalRepresentation >= iso8859_1_start_first && decimalRepresentation <= iso8859_1_end_first) ||
(decimalRepresentation >= iso8859_1_start_second && decimalRepresentation <= iso8859_1_end_second))
{
// If any invalid code point is found, return false
// Check if the code point is in the range of valid characters
const validRanges = [
{ start: iso8859_1_start_first, end: iso8859_1_end_first },
{ start: iso8859_1_start_second, end: iso8859_1_end_second }
];

const isValidCharacter = validRanges.some(range => {
return decimalRepresentation >= range.start && decimalRepresentation <= range.end;
});

if (!isValidCharacter) {
return false;
}
}
Expand Down

0 comments on commit 1ae9a6f

Please sign in to comment.