-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from zowe/typoLoop_Fix
fix to disallow invalid characters in filenames
- Loading branch information
Showing
4 changed files
with
108 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
* | ||
*/ | ||
|
||
export class Utilities{ | ||
/** | ||
* Check to ensure filename only contains valid characters | ||
* @param {fileName} string - filename to be evaluated | ||
* @returns {Promise<boolean>} - promise that resolves to true if filename contains valid characters | ||
* @memberof Utilities | ||
*/ | ||
public static isValidFileName(fileName: string): boolean { | ||
// Define valid character ranges for ISO/IEC 8859-1 https://en.wikipedia.org/wiki/ISO/IEC_8859-1 | ||
const validRanges = [ | ||
{ start: 32, end: 127 }, // First chunk of valid characters | ||
{ start: 160, end: 255 } // Second chunk of valid characters | ||
]; | ||
|
||
// Check if each character in the filename is within a valid range | ||
for (const char of fileName) { | ||
const charCode = char.charCodeAt(0); | ||
if (!validRanges.some(range => charCode >= range.start && charCode <= range.end)) { | ||
return false; | ||
} | ||
} | ||
|
||
return 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