input.webkitEntries does not work as expected when folder contains accented chars
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 03:55:51 +0000 (03:55 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 03:55:51 +0000 (03:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184517
<rdar://problem/39265537>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Use String::fromUTF8() to construct a WTF String from the char* returned by
dirname() in FileSystem::directoryName(). Previously, we were just calling
the String constructor, which would treat the input as latin 1 instead of
UTF-8.

Test: fast/forms/file/entries-api/webkitEntries-nonascii-folder-name.html

* platform/posix/FileSystemPOSIX.cpp:
(WebCore::FileSystem::directoryName):

LayoutTests:

Add layout test coverage.

* fast/forms/file/entries-api/webkitEntries-nonascii-folder-name-expected.txt: Added.
* fast/forms/file/entries-api/webkitEntries-nonascii-folder-name.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230554 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/file/entries-api/resources/älo/test.txt [new file with mode: 0644]
LayoutTests/fast/forms/file/entries-api/webkitEntries-nonascii-folder-name-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/file/entries-api/webkitEntries-nonascii-folder-name.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/posix/FileSystemPOSIX.cpp

index cbc6886..41e2da4 100644 (file)
@@ -1,3 +1,16 @@
+2018-04-11  Chris Dumez  <cdumez@apple.com>
+
+        input.webkitEntries does not work as expected when folder contains accented chars
+        https://bugs.webkit.org/show_bug.cgi?id=184517
+        <rdar://problem/39265537>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add layout test coverage.
+
+        * fast/forms/file/entries-api/webkitEntries-nonascii-folder-name-expected.txt: Added.
+        * fast/forms/file/entries-api/webkitEntries-nonascii-folder-name.html: Added.
+
 2018-04-11  Youenn Fablet  <youenn@apple.com>
 
         Preventively expect UTF8 strings from libwebrtc SDP and error messages
diff --git a/LayoutTests/fast/forms/file/entries-api/resources/älo/test.txt b/LayoutTests/fast/forms/file/entries-api/resources/älo/test.txt
new file mode 100644 (file)
index 0000000..2a02d41
--- /dev/null
@@ -0,0 +1 @@
+TEST
diff --git a/LayoutTests/fast/forms/file/entries-api/webkitEntries-nonascii-folder-name-expected.txt b/LayoutTests/fast/forms/file/entries-api/webkitEntries-nonascii-folder-name-expected.txt
new file mode 100644 (file)
index 0000000..fc86dab
--- /dev/null
@@ -0,0 +1,15 @@
+OPEN FILE PANEL
+Tests webkitEntries when the path includes a folder with a non-ascii character in its name.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS entries.length is 1
+PASS entry.name is "test.txt"
+PASS entry.fullPath is "/test.txt"
+PASS entry.isFile is true
+PASS contentResult is "TEST\n"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/file/entries-api/webkitEntries-nonascii-folder-name.html b/LayoutTests/fast/forms/file/entries-api/webkitEntries-nonascii-folder-name.html
new file mode 100644 (file)
index 0000000..890bbeb
--- /dev/null
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<script src="../../../../resources/js-test.js"></script>
+<script src="../../../../resources/ui-helper.js"></script>
+</head>
+<body>
+<input type="file" onchange="changed(event)">
+<script>
+description("Tests webkitEntries when the path includes a folder with a non-ascii character in its name.");
+jsTestIsAsync = true;
+
+function runTest()
+{
+    testRunner.setOpenPanelFiles(['resources/älo/test.txt']);
+
+    inputElement = document.getElementsByTagName('input')[0];
+    UIHelper.activateAt(inputElement.offsetLeft + inputElement.offsetWidth / 2, inputElement.offsetTop + inputElement.offsetHeight / 2);
+}
+
+function fileAsPromise(fileEntry)
+{
+    return new Promise((resolve, reject) => {
+        fileEntry.file(resolve, reject);
+    });
+}
+
+function readTextFileAsPromise(file)
+{
+    return new Promise((resolve, reject) => {
+        let fileReader = new FileReader();
+        fileReader.onload = function(e) {
+            resolve(fileReader.result);
+        }
+        fileReader.readAsText(file);
+    });
+}
+
+function getFileAsPromise(directoryEntry, path)
+{
+    return new Promise((resolve, reject) => {
+        directoryEntry.getFile(path, {}, resolve, reject);
+    });
+}
+
+function changed(event)
+{
+    entries = event.target.webkitEntries;
+    shouldBe("entries.length", "1");
+
+    entry = entries[0];
+    shouldBeEqualToString("entry.name", "test.txt");
+    shouldBeEqualToString("entry.fullPath", "/test.txt");
+    shouldBeTrue("entry.isFile");
+
+    fileAsPromise(entry).then(file => {
+        return readTextFileAsPromise(file).then(content => {
+           contentResult = content;
+           shouldBeEqualToString("contentResult", "TEST\n");
+           finishJSTest();
+       }, e => {
+           testFailed("Reading file contents failed unexpectedly: " + e);
+           finishJSTest();
+       });
+    }, e => {
+        testFailed("fileEntry.file() call failed unexpectedly: " + e);
+        finishJSTest();
+    });
+}
+
+runTest();
+</script>
+</body>
+</html>
index 8ef9f82..07f3f80 100644 (file)
@@ -1,3 +1,21 @@
+2018-04-11  Chris Dumez  <cdumez@apple.com>
+
+        input.webkitEntries does not work as expected when folder contains accented chars
+        https://bugs.webkit.org/show_bug.cgi?id=184517
+        <rdar://problem/39265537>
+
+        Reviewed by Ryosuke Niwa.
+
+        Use String::fromUTF8() to construct a WTF String from the char* returned by
+        dirname() in FileSystem::directoryName(). Previously, we were just calling
+        the String constructor, which would treat the input as latin 1 instead of
+        UTF-8.
+
+        Test: fast/forms/file/entries-api/webkitEntries-nonascii-folder-name.html
+
+        * platform/posix/FileSystemPOSIX.cpp:
+        (WebCore::FileSystem::directoryName):
+
 2018-04-11  Youenn Fablet  <youenn@apple.com>
 
         Preventively expect UTF8 strings from libwebrtc SDP and error messages
index 1997d24..4da7cf6 100644 (file)
@@ -351,7 +351,7 @@ String directoryName(const String& path)
     if (!fsRep.data() || fsRep.data()[0] == '\0')
         return String();
 
-    return dirname(fsRep.mutableData());
+    return String::fromUTF8(dirname(fsRep.mutableData()));
 }
 
 Vector<String> listDirectory(const String& path, const String& filter)