Skip to content

Commit

Permalink
Add restrictions to allowed extensions for File System Access API
Browse files Browse the repository at this point in the history
These restrictions apply to showOpenFilePicker and showSaveFilePicker.

Existing restriction:
- Extension must start with "."

New restrictions:
- Allowed code points: [A-Za-z0-9+.]
- Extension length cannot exceed to 16, inclusive of leading "."
- Extension cannot end with "."
- Extension cannot end with "local" or "lnk"

Bug: 1137247, 1140410, 1140417, 1152327
Change-Id: I593f7ca60e05177402885bd3026add16b3a07d0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568534
Reviewed-by: Marijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833695}
  • Loading branch information
a-sully authored and chromium-wpt-export-bot committed Dec 4, 2020
1 parent a8fad46 commit eb57287
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions native-file-system/showPicker-errors.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,39 @@ function define_file_picker_error_tests(showPickerMethod) {
showPickerMethod +
': MIME type can\'t have invalid characters in subtype.');

promise_test(async t => {
await promise_rejects_js(t, TypeError, self[showPickerMethod]({
types: [{accept: {'text/plain': ['.txt', 'txt']}}]
}));
}, showPickerMethod + ': extension has to start with ".".');
const invalid_extensions = {
'.extensiontoolong': 'extension length more than 16.',
'.txt.': 'extenstion ends with "."',
'txt': 'extenstion does not start with "."',
'.$txt' : 'illegal character "$"',
'.t<xt': 'illegal character "<"',
'.t/xt': 'illegal character "\"',
'.\txt': 'illegal character "/"',
'.txt\\': 'illegal characters "\\"',
'.txt?': 'illegal character "?"',
'.txt*': 'illegal character "*"',
'.{txt': 'illegal character "{"',
'.}txt': 'illegal character "}"',
' .txt': 'illegal whitespace at front of extension',
'. txt': 'illegal whitespace in extension',
'.txt ': 'illegal whitespace at end of extension',
'.\u202etxt\u202e' : 'illegal RTL character',
'.t\u00E6xt': 'non-ASCII character "æ"',
'.קום': 'non-ASCII character "קום"',
'.txt🙂': 'non-ASCII character "🙂"',
'.{txt}': 'illegal characters "{" and "}"',
}

for (const [extension, description] of Object.entries(invalid_extensions)) {
define_file_picker_extension_error_test(showPickerMethod, extension, description)
}
}

function define_file_picker_extension_error_test(showPickerMethod, extension, description) {
promise_test(async t => {
await promise_rejects_js(
t, TypeError,
self[showPickerMethod](
{ types: [{ accept: { 'text/plain': ['.txt', extension] } }] }));
}, showPickerMethod + ': invalid extension "' + extension + '". ' + description + ".");
}

0 comments on commit eb57287

Please sign in to comment.