fix: read a typed folder the same in both modes

Line mode dropped quotes only when both ends had one, so a half-selected
paste made a folder whose name starts with a quote. The screen's reader
is now the only one: any quote at either end goes, variables expand
before ~.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:04:39 +01:00
1 parent ee2e6e80ce
commit 8c74f3f0bc
7 files changed
+27 -31

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
# the site's build rewrites this line there (scripts/sitebootstrap.py).
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
$defaultInstallSha256 = "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812"
$defaultInstallSha256 = "eed68111561f629fcdd392da968628eb9f7a543a8b4d2f82bdd6931ebc9d532d"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
$maximumInstallerBytes = 8MB
+6 -9
View File
@@ -2080,13 +2080,12 @@ def _typed_folder(raw: str) -> Path:
Explorer's "Copy as path" puts quotes around it, and users quote a path
with spaces: kept, they sent the files into a folder named `"` under
the current directory, and the run said Done.
the current directory, and the run said Done. A half-selected copy
quotes one end only.
"""
text = raw.strip()
if len(text) >= 2 and text[0] == text[-1] and text[0] in "'\"":
text = text[1:-1].strip()
text = raw.strip().strip("\"'").strip()
# Under WSL, D: and D:\ are the Windows drive the screen calls D:.
return _host_path(os.path.expandvars(os.path.expanduser(text)))
return _host_path(os.path.expanduser(os.path.expandvars(text)))
def _ask(prompt: str) -> str:
@@ -28906,11 +28905,9 @@ def _open_folder_screen(state: TuiState, default: Path | None,
def typed_path(text: str) -> Path | None:
"""A folder typed or pasted: quotes off, ~ and variables expanded."""
# Explorer's "Copy as path" quotes both ends, a half-selected copy one.
text = text.strip().strip("\"'").strip()
if not text:
if not text.strip().strip("\"'").strip():
return None
return _host_path(os.path.expanduser(os.path.expandvars(text)))
return _typed_folder(text)
def _tui_folder_facts(state: TuiState) -> dict:
+1 -1
View File
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
# curl or wget stop on a cut transfer before the hash is read: the site's
# build rewrites this line there (scripts/sitebootstrap.py).
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
DEFAULT_INSTALL_SHA256="24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812"
DEFAULT_INSTALL_SHA256="eed68111561f629fcdd392da968628eb9f7a543a8b4d2f82bdd6931ebc9d532d"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
MAX_INSTALLER_BYTES=8388608
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1449658,
"sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812",
"size": 1449494,
"sha256": "eed68111561f629fcdd392da968628eb9f7a543a8b4d2f82bdd6931ebc9d532d",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1503283,
"sha256": "5e53ba1ca6d7fe47789b84fe1aaaba50e3752454ffc182389bd83e1f905baca1"
"size": 1503119,
"sha256": "83cbb67cf4c2f9244e2112f6326fdf6874dfd48998cb017f56979670f3d34b6a"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1449658,
"sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812",
"size": 1449494,
"sha256": "eed68111561f629fcdd392da968628eb9f7a543a8b4d2f82bdd6931ebc9d532d",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1449658,
"sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812",
"size": 1449494,
"sha256": "eed68111561f629fcdd392da968628eb9f7a543a8b4d2f82bdd6931ebc9d532d",
"executable": false
},
{
+4 -5
View File
@@ -19,13 +19,12 @@ def _typed_folder(raw: str) -> Path:
Explorer's "Copy as path" puts quotes around it, and users quote a path
with spaces: kept, they sent the files into a folder named `"` under
the current directory, and the run said Done.
the current directory, and the run said Done. A half-selected copy
quotes one end only.
"""
text = raw.strip()
if len(text) >= 2 and text[0] == text[-1] and text[0] in "'\"":
text = text[1:-1].strip()
text = raw.strip().strip("\"'").strip()
# Under WSL, D: and D:\ are the Windows drive the screen calls D:.
return _host_path(os.path.expandvars(os.path.expanduser(text)))
return _host_path(os.path.expanduser(os.path.expandvars(text)))
def _ask(prompt: str) -> str:
+4 -6
View File
@@ -19,7 +19,7 @@ from installer.cards import (
card_system,
)
from installer.choices import emulator_names
from installer.console import QUIT_CODE
from installer.console import QUIT_CODE, _typed_folder
from installer.cores import CORE_PLATFORMS, core_dirs, installed_cores
from installer.destination import (
_card_is,
@@ -33,7 +33,7 @@ from installer.destination import (
from installer.detect_os import _DETECTED_OS, _FROM_CARD, detected_os, detected_shown
from installer.embedded import CARD_PLATFORMS, _a
from installer.games import games_probe
from installer.host_fs import _exists, _folder_writable, _host_path, _is_dir, _nearest_folder, closed_folder
from installer.host_fs import _exists, _folder_writable, _is_dir, _nearest_folder, closed_folder
from installer.install_record import RECORD_NARROWING, _RECORD_SAID, record_options, setup_record
from installer.invocation import OFFLINE_VARIABLE, offline_requested
from installer.network import local_targets
@@ -732,11 +732,9 @@ def _open_folder_screen(state: TuiState, default: Path | None,
def typed_path(text: str) -> Path | None:
"""A folder typed or pasted: quotes off, ~ and variables expanded."""
# Explorer's "Copy as path" quotes both ends, a half-selected copy one.
text = text.strip().strip("\"'").strip()
if not text:
if not text.strip().strip("\"'").strip():
return None
return _host_path(os.path.expanduser(os.path.expandvars(text)))
return _typed_folder(text)
def _tui_folder_facts(state: TuiState) -> dict:
+3 -1
View File
@@ -2218,7 +2218,9 @@ class TestManualPlatformPrompt(unittest.TestCase):
folder named `"` under the current directory, and the run said Done."""
root = Path(_tempdir(self))
for typed in (f'"{root}/My Card/bios"', f"'{root}/My Card/bios'",
f' "{root}/My Card/bios" '):
f' "{root}/My Card/bios" ',
# A half-selected copy: line mode kept the quote.
f'"{root}/My Card/bios'):
answers = iter(["1", typed])
with self.subTest(typed=typed), \
unittest.mock.patch("builtins.input",