Skip to content

don't mistake a malformed URL for a local path, #10215 - #10216

Open
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:fix-rest-url-parsing-10215
Open

don't mistake a malformed URL for a local path, #10215#10216
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:fix-rest-url-parsing-10215

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Fixes the confusing behaviour reported in discussion #10215: borg -r rest://dcm/ repo-info failed with

Repository proto='file', user=None, pass=None, host=None, port=None, path='/home/borg/rest:/dcm' does not exist.

Cause

rest://dcm/ carries no repository path, so it does not match rest_re (which needs at least one
character after the separating slash). It then fell through to local_re, whose negative lookahead
excluded ssh://, file:// and the borgstore schemes, but not rest://. So the URL was taken
for a relative local path and prefixed with the cwd.

Change

All schemes borg parses itself (ssh, rest, file) are now excluded from local_re, in the
opaque scheme: form as well as in the scheme:// form. Nothing starting with those prefixes can
silently become a local path any more - such input is rejected instead. A local path that really
starts with such a prefix can still be given as ./rest:... or as an absolute path (there is a test
for that).

The reporter said they had tried numerous permutations without getting any useful feedback, so the
error now also names the accepted forms:

error: argument -r/--repo: Invalid location format: "rest://dcm/". Expected: rest://[user@]host[:port]/path/to/repo (path relative to the remote directory ssh logs into) or rest://[user@]host[:port]//path/to/repo (absolute path)

Docs

  • quickstart.rst recommended rest://borg@remote_host (no path), which would have run into
    exactly this error.
  • The repository URL reference called the single-slash form "path relative to the current directory"
    for the remote protocols, but it is relative to the remote login directory. Corrected for
    rest/ssh/sftp, and added a note that the path is required and what one vs. two slashes mean.

Tests

New tests cover the malformed rest:// forms, the hint per scheme, local paths starting with a
scheme name, and rest:// canonical-path round trips. Full test suite passes locally.

A "rest://host/" URL (no repository path) did not match rest_re, fell through
to local_re and became the local directory "./rest:/host", which then failed
with a confusing "Repository ... does not exist" message. Only "ssh://" and
"file://" were excluded from local_re, "rest://" was not.

Exclude all schemes borg parses itself from local_re, in the opaque form too,
so no "rest:...", "ssh:..." or "file:..." input can silently be taken for a
local path, and tell the accepted forms when such a URL does not parse.

A local path that really starts with such a prefix can still be given as
"./rest:..." or as an absolute path.
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.29%. Comparing base (29022db) to head (132e0c3).
⚠️ Report is 12 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10216      +/-   ##
==========================================
- Coverage   87.29%   87.29%   -0.01%     
==========================================
  Files         102      102              
  Lines       18444    18451       +7     
  Branches     2834     2834              
==========================================
+ Hits        16101    16107       +6     
  Misses       1638     1638              
- Partials      705      706       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant