瀏覽代碼

handle emoji favicons with \uFE0F "Variation Selector-16" (fixes #2888)

Falko Schindler 1 年之前
父節點
當前提交
10d8172af8
共有 2 個文件被更改,包括 6 次插入4 次删除
  1. 1 1
      nicegui/favicon.py
  2. 5 3
      tests/test_favicon.py

+ 1 - 1
nicegui/favicon.py

@@ -66,7 +66,7 @@ def _is_remote_url(favicon: str) -> bool:
 
 
 def _is_char(favicon: str) -> bool:
-    return len(favicon) == 1
+    return len(favicon) == 1 or '\ufe0f' in favicon
 
 
 def _is_svg(favicon: str) -> bool:

+ 5 - 3
tests/test_favicon.py

@@ -1,6 +1,7 @@
 from pathlib import Path
 from typing import Union
 
+import pytest
 import requests
 from bs4 import BeautifulSoup
 
@@ -37,13 +38,14 @@ def test_default(screen: Screen):
     assert_favicon(DEFAULT_FAVICON_PATH)
 
 
-def test_emoji(screen: Screen):
+@pytest.mark.parametrize('emoji', ['👋', '⚔️'])
+def test_emoji(emoji: str, screen: Screen):
     ui.label('Hello, world')
 
-    screen.ui_run_kwargs['favicon'] = '👋'
+    screen.ui_run_kwargs['favicon'] = emoji
     screen.open('/')
     assert_favicon_url_starts_with(screen, 'data:image/svg+xml')
-    assert_favicon(favicon._char_to_svg('👋'))
+    assert_favicon(favicon._char_to_svg(emoji))
 
 
 def test_data_url(screen: Screen):