forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue using a local path with
st.image
on windows. (streamlit#8092
) ## Describe your changes This PR fixes an issue with using image files via a local path on Windows (streamlit#7271). This also unifies all URL checks in the Streamlit server with a Python native implementation and cuts out the `validators` dependency. ## GitHub Issue Link (if applicable) - Closes streamlit#7271 ## Testing Plan - Updated tests --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
- Loading branch information
1 parent
e2a8204
commit 60d0ee6
Showing
10 changed files
with
144 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,4 @@ toml==0.10.1 | |
tornado==6.0.3 | ||
typing-extensions==4.3.0 | ||
tzlocal==1.1 | ||
validators==0.2 | ||
watchdog==2.1.5 |
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
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
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 |
---|---|---|
|
@@ -17,12 +17,7 @@ | |
from parameterized import param, parameterized | ||
|
||
import streamlit as st | ||
from streamlit.commands.page_config import ( | ||
ENG_EMOJIS, | ||
RANDOM_EMOJIS, | ||
PageIcon, | ||
valid_url, | ||
) | ||
from streamlit.commands.page_config import ENG_EMOJIS, RANDOM_EMOJIS, PageIcon | ||
from streamlit.errors import StreamlitAPIException | ||
from streamlit.proto.PageConfig_pb2 import PageConfig as PageConfigProto | ||
from streamlit.string_util import is_emoji | ||
|
@@ -154,20 +149,3 @@ def test_set_page_config_menu_items_empty_dict(self): | |
st.set_page_config(menu_items={}) | ||
c = self.get_message_from_queue().page_config_changed.menu_items | ||
self.assertEqual(c.about_section_md, "") | ||
|
||
@parameterized.expand( | ||
[ | ||
("http://www.cwi.nl:80/%7Eguido/Python.html", True), | ||
("/data/Python.html", False), | ||
(532, False), | ||
("dkakasdkjdjakdjadjfalskdjfalk", False), | ||
("https://stackoverflow.com", True), | ||
("mailto:[email protected]", True), | ||
("mailto:", False), | ||
] | ||
) | ||
def test_valid_url(self, url, expected_value): | ||
if expected_value: | ||
self.assertTrue(valid_url(url)) | ||
else: | ||
self.assertFalse(valid_url(url)) |
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 |
---|---|---|
|
@@ -12,7 +12,12 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
import unittest | ||
from typing import Any, Tuple | ||
|
||
from parameterized import parameterized | ||
|
||
from streamlit import url_util | ||
|
||
|
@@ -63,13 +68,70 @@ | |
|
||
class GitHubUrlTest(unittest.TestCase): | ||
def test_github_url_is_replaced(self): | ||
for (target, processed) in GITHUB_URLS: | ||
for target, processed in GITHUB_URLS: | ||
assert url_util.process_gitblob_url(target) == processed | ||
|
||
def test_gist_url_is_replaced(self): | ||
for (target, processed) in GIST_URLS: | ||
for target, processed in GIST_URLS: | ||
assert url_util.process_gitblob_url(target) == processed | ||
|
||
def test_nonmatching_url_is_not_replaced(self): | ||
for url in INVALID_URLS: | ||
assert url == url_util.process_gitblob_url(url) | ||
|
||
|
||
class UrlUtilTest(unittest.TestCase): | ||
@parameterized.expand( | ||
[ | ||
# Valid URLs: | ||
("http://www.cwi.nl:80/%7Eguido/Python.html", True), | ||
("https://stackoverflow.com", True), | ||
("mailto:[email protected]", True), | ||
("data:image/svg+xml;base64,PHN2ZyB4aHcvMjAwMC9zdmci", True), | ||
("data:application/pdf;base64,PHN2ZyB4aHcvMjAwMC9zdmci", True), | ||
("http://127.0.0.1", True), # IP as domain | ||
("https://[::1]", True), # IPv6 address in URL | ||
# Invalid URLs: | ||
("/data/Python.html", False), | ||
("www.streamlit.io", False), # Missing scheme | ||
(532, False), | ||
("dkakasdkjdjakdjadjfalskdjfalk", False), | ||
("mailto:", False), | ||
("ftp://example.com/resource", False), # Unsupported scheme | ||
("https:///path/to/resource", False), # Missing netloc | ||
] | ||
) | ||
def test_is_url(self, url: Any, expected_value: bool): | ||
"""Test the is_url utility function.""" | ||
self.assertEqual( | ||
url_util.is_url(url, ("http", "https", "data", "mailto")), expected_value | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
("http://example.com", ("http",), True), | ||
("mailto:[email protected]", ("http", "https"), False), | ||
("mailto:[email protected]", ("http", "mailto"), True), | ||
("https://example.com", ("http",), False), | ||
("https://example.com", ("https",), True), | ||
("data:image/png;base64,abc123", ("data",), True), | ||
("data:image/png;base64,abc123", ("http", "https", "mailto"), False), | ||
("https://example.com", ("http", "https", "mailto"), True), | ||
("http://example.com", None, True), # None schema == use default | ||
("https://example.com", None, True), # None schema == use default | ||
("data:image/png;base64,abc123", None, False), # None schema == use default | ||
("mailto:[email protected]", None, False), # None schema == use default | ||
] | ||
) | ||
def test_is_url_limits_schema( | ||
self, | ||
url: str, | ||
allowed_schemas: Tuple[url_util.UrlSchema, ...] | None, | ||
expected_value: bool, | ||
): | ||
"""Test that is_ur applies the allowed schema parameter.""" | ||
|
||
if allowed_schemas is None: | ||
self.assertEqual(url_util.is_url(url), expected_value) | ||
else: | ||
self.assertEqual(url_util.is_url(url, allowed_schemas), expected_value) |
Oops, something went wrong.