Commit b4be0a86 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

WebShare: Allow downloaded web pages to be shared

When a web page is downloaded in Android, and then shared using WebShare,
the "file name" reported to WebShare starts with "https://".

This patch allows such files to be shared.

Bug: 965461
Change-Id: If1922c81ade874bb7b8be06d88361e10b2db248b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1624525Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666588}
parent 345cff5d
...@@ -254,7 +254,8 @@ public class ShareServiceImpl implements ShareService { ...@@ -254,7 +254,8 @@ public class ShareServiceImpl implements ShareService {
} }
static boolean isDangerousFilename(String name) { static boolean isDangerousFilename(String name) {
return name.indexOf('/') != -1 || name.indexOf('\\') != -1 || name.indexOf('.') <= 0 // Reject filenames without a permitted extension.
return name.indexOf('.') <= 0
|| !PERMITTED_EXTENSIONS.contains(FileUtils.getExtension(name)); || !PERMITTED_EXTENSIONS.contains(FileUtils.getExtension(name));
} }
......
...@@ -21,15 +21,18 @@ import org.chromium.base.test.BaseRobolectricTestRunner; ...@@ -21,15 +21,18 @@ import org.chromium.base.test.BaseRobolectricTestRunner;
public class ShareServiceImplTest { public class ShareServiceImplTest {
@Test @Test
@SmallTest @SmallTest
public void testSlash() { public void testExtensionFormatting() {
Assert.assertTrue(ShareServiceImpl.isDangerousFilename("foo/bar.txt")); Assert.assertFalse(ShareServiceImpl.isDangerousFilename("foo/bar.txt"));
Assert.assertTrue(ShareServiceImpl.isDangerousFilename("foo\\bar.txt")); Assert.assertFalse(ShareServiceImpl.isDangerousFilename("foo\\bar\u03C0.txt"));
} Assert.assertTrue(ShareServiceImpl.isDangerousFilename("foo\\bar.tx\u03C0t"));
Assert.assertFalse(ShareServiceImpl.isDangerousFilename("https://example.com/a/b.html"));
@Test Assert.assertTrue(ShareServiceImpl.isDangerousFilename("foo/bar.txt/"));
@SmallTest Assert.assertTrue(ShareServiceImpl.isDangerousFilename("foobar.tx\\t"));
public void testPeriod() {
Assert.assertTrue(ShareServiceImpl.isDangerousFilename("hello")); Assert.assertTrue(ShareServiceImpl.isDangerousFilename("hello"));
Assert.assertTrue(ShareServiceImpl.isDangerousFilename("hellotxt"));
Assert.assertTrue(ShareServiceImpl.isDangerousFilename(".txt"));
Assert.assertFalse(ShareServiceImpl.isDangerousFilename("https://example.com/a/.txt"));
Assert.assertFalse(ShareServiceImpl.isDangerousFilename("/.txt"));
Assert.assertTrue(ShareServiceImpl.isDangerousFilename("..")); Assert.assertTrue(ShareServiceImpl.isDangerousFilename(".."));
Assert.assertTrue(ShareServiceImpl.isDangerousFilename(".hello.txt")); Assert.assertTrue(ShareServiceImpl.isDangerousFilename(".hello.txt"));
} }
......
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