Skip to content

fix: handle undefined pathname in URL builder#2021

Open
UnschooledGamer wants to merge 11 commits intoAcode-Foundation:mainfrom
UnschooledGamer:fix/url-no-doc-id
Open

fix: handle undefined pathname in URL builder#2021
UnschooledGamer wants to merge 11 commits intoAcode-Foundation:mainfrom
UnschooledGamer:fix/url-no-doc-id

Conversation

@UnschooledGamer
Copy link
Copy Markdown
Member

@UnschooledGamer UnschooledGamer commented Apr 9, 2026

Return early when pathname is undefined to avoid inserting an extra ':' and strip a leading '/' from newDocId before concatenation

  • Adds Tests for URL joining for Android, acode terminal and Termux URIs.
  • Bumps Biome to ^2.4.11

Return early when pathname is undefined to avoid inserting an extra ':'
and strip a leading '/' from newDocId before concatenation
@UnschooledGamer
Copy link
Copy Markdown
Member Author

UnschooledGamer commented Apr 9, 2026

Oh no, biome didn't complain locally.

We'll be fixed before merging

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 9, 2026

Greptile Summary

This PR adds an early-return guard in Url.join when pathname is undefined (i.e., the content URI's docId contains no : separator), preventing a spurious : from being injected into the returned URI. The separator-normalization logic between root and newDocId correctly handles all four slash-presence combinations and matches the approach suggested in prior review discussion.

Confidence Score: 5/5

Safe to merge; the fix is logically correct and the only remaining finding is a test-coverage gap (P2).

The undefined-pathname separator logic is correct across all four slash-presence combinations, prior P1 concerns from earlier review rounds have been addressed, and the single open finding is a P2 suggestion to add a test for the specific code path the fix introduces.

src/test/url.tests.js — none of the new tests exercise the !pathname branch added in Url.js.

Important Files Changed

Filename Overview
src/utils/Url.js Adds early-return block when pathname is undefined to avoid injecting an extra :, with correct separator-normalization between root and newDocId; logic is sound but the undefined-pathname path is not exercised by the new tests.
src/test/url.tests.js New test suite for SAF/content URI joins; all cases use URLs with ::docId:path where pathname is always defined, so the newly added !pathname code path is never exercised.
src/test/tester.js Imports and registers the new runUrlTests alongside the existing test suites; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Url.join(...pathnames)"] --> B{protocol === 'content://'?}
    B -- No --> C["path.join / protocol join"]
    B -- Yes --> D["Strip leading '/' from pathnames[1]"]
    D --> E["Uri.parse → rootUri, docId"]
    E --> F["docId.split(':') → [root, pathname]"]
    F --> G["newDocId = path.join(pathname, ...pathnames.slice(1))"]
    G --> H{Termux URL?}
    H -- Yes --> I["Normalize root/newDocId separators\nReturn rootUri::root+newDocId"]
    H -- No --> J{"pathname undefined?\n(!pathname)"}
    J -- Yes --> K["Normalize separator between\nroot and newDocId"]
    K --> L["Return rootUri::root+separator+newDocId\n(no extra ':')"] 
    J -- No --> M["Return rootUri::root:newDocId"]
Loading

Reviews (5): Last reviewed commit: "Merge branch 'fix/url-no-doc-id' of http..." | Re-trigger Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@UnschooledGamer

This comment was marked as outdated.

@UnschooledGamer

This comment was marked as outdated.

@UnschooledGamer UnschooledGamer marked this pull request as draft April 10, 2026 06:12
Move pathname handling into the correct branch and ensure a ':' is
inserted between root and newDocId when appropriate
@UnschooledGamer UnschooledGamer marked this pull request as ready for review April 10, 2026 06:52
@UnschooledGamer

This comment was marked as outdated.

@UnschooledGamer

This comment was marked as resolved.

@UnschooledGamer
Copy link
Copy Markdown
Member Author

UnschooledGamer commented Apr 10, 2026

The new tests do use !pathname branch, which is when Acode's Terminal URIs occur, that extracts pathname to undefined as there's no more : (unlike in Android SAF URIs for Acode) in the docId.

Linting CI fails due to commits from upstream.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant