Commit 4bcaa260 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Make explicit the allowed external drive labels

This mimics how cros-disks does external drive label validation. See
http://crrev.com/c/1697542 for the cros-disks change.

Bug: 983044
Change-Id: I460523bc7a3856a94328160b992052b700744d3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1941454
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719895}
parent b6cb1ff0
......@@ -1241,21 +1241,6 @@ util.isDropEffectAllowed = (effectAllowed, dropEffect) => {
effectAllowed.toLowerCase().indexOf(dropEffect) !== -1;
};
/**
* Checks if the specified character is printable ASCII.
*
* @param {string} character The input character.
* @return {boolean} True if |character| is printable ASCII, else false.
*/
util.isPrintable = character => {
if (character.length != 1) {
return false;
}
const charCode = character.charCodeAt(0);
return charCode >= 32 && charCode <= 126;
};
/**
* Verifies the user entered name for file or folder to be created or
* renamed to. Name restrictions must correspond to File API restrictions
......@@ -1326,22 +1311,17 @@ util.validateExternalDriveName = (name, fileSystem) => {
strf('ERROR_EXTERNAL_DRIVE_LONG_NAME', lengthLimit[fileSystem]));
}
// Checks if name contains only printable ASCII (from ' ' to '~')
// Checks if the name contains only alphanumeric characters or allowed special
// characters. This needs to stay in sync with cros-disks/filesystem_label.cc
// on the ChromeOS side.
const validCharRegex = /[a-zA-Z0-9 \!\#\$\%\&\(\)\-\@\^\_\`\{\}\~]/;
for (let i = 0; i < nameLength; i++) {
if (!util.isPrintable(name[i])) {
if (!validCharRegex.test(name[i])) {
return Promise.reject(
strf('ERROR_EXTERNAL_DRIVE_INVALID_CHARACTER', name[i]));
}
}
const containsForbiddenCharacters =
/[\*\?\.\,\;\:\/\\\|\+\=\<\>\[\]\"\'\t]/.exec(name);
if (containsForbiddenCharacters) {
return Promise.reject(strf(
'ERROR_EXTERNAL_DRIVE_INVALID_CHARACTER',
containsForbiddenCharacters[0]));
}
return Promise.resolve();
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment