Commit Graph

38 Commits

Author SHA1 Message Date
Kat
6fabf775bb Lots of duplicate word typos + typo. 2026-03-16 09:19:09 +11:00
Ben Kircher
f66064b0b0 url: fix regression with unified diff lines
Bare relative paths don't need space-continuation semantics.

Fixes #10773
2026-02-19 21:06:56 +01:00
Ben Kircher
c5488afc75 url: improve space in path handling
The space-segment patterns in the path regex (dotted_path_space_segments
and any_path_space_segments) greedily consume text after a space even
when we know that the text is the start of a new independent path (e.g.,
`/tmp/bar` in `/tmp/foo /tmp/bar`).

Fix: Add two negative lookaheads after the space in both patterns:
- `(?!\.{0,2}\/)` →  don't match if the next segment starts with `/`,
  `./`, or `../`
- `(?!~\/)` →  don't match if the next segment starts with `~/`
2026-02-19 21:06:56 +01:00
Ben Kircher
7d87a58a73 url: fix trailing colon in path matches
Paths like `./.config/ghostty:` and `./Downloads:` were incorrectly
including the trailing colon. Add a `no_trailing_colon` lookbehind to
all path branches and prevent space segments from starting after a colon
so that `": text"` is not consumed as part of the path.
2026-02-14 09:42:07 +01:00
Ben Kircher
bbcc22746a urls: fix over-matching single spaced paths
This commit adds a negative lookahead `(?!\w+://)` to both
`dotted_path_space_segments` and `any_path_space_segments`. This
prevents the space-segment matching from consuming text that starts with
a URL scheme (like http://), which was causing /tmp/test.txt
http://www.google.com to over-match.

Fixes
https://github.com/ghostty-org/ghostty/issues/1972#issuecomment-3882254792
2026-02-11 09:47:28 +01:00
Ben Kircher
50ba394ed3 url: do not match on //
Double-slash comments are not paths so do not match on them.
2026-02-11 09:34:52 +01:00
Ben Kircher
23d22c457a url: fix , handling for spaced paths
Update path_space_segments patterns to consistently handle
comma-delimiters.
2026-02-11 09:34:52 +01:00
Ben Kircher
38831436ea url: fix tilde mid-word partial matches
Don't match `~` mid-word or before `/`.
2026-02-11 09:34:52 +01:00
Ben Kircher
270ee5468f url: fix $VAR mid-word partial matches
Add `(?<!\w)` to prefixes so that $VAR cannot match mid-word.
2026-02-11 09:34:52 +01:00
Ben Kircher
02749cb1dc url: fix comma handling
This string

    foo/bar,baz.txt

should not match but

    src/foo.c,baz.txt

should.

Remove `,` from dotted_path_lookahead and non_dotted_path_lookahead.
2026-02-11 09:34:52 +01:00
Ben Kircher
19a41eb26b url: allow numeric characters at start
Amends and fixes the last commit which was too simpel. This commit uses
a lookbehind to prevent matching $-numeric patterns.
2026-02-11 09:34:52 +01:00
Ben Kircher
99320714bc url: fix incomplete $-numeric behavior
This

    $10/bar.txt

was partially matching but should not match at all.

This commit fixes this by simply `[\w]` to `[A-Za-z_]` as the first
character of a bare relative path, so digit-starting fragments can't
match.

Another option would be a lookbehind but I think the check above is much
simpler.
2026-02-11 09:34:52 +01:00
Ben Kircher
77ee47c18f url: fix partial match of mid string $-variable
A string like this

    foo/$BAR/baz

should match fully, not partially.

This commit fixes this by expanding `\$[A-Za-z_]\w*\/` to
`(?:[\w][\w\-.]*\/)*\$[A-Za-z_]\w*\/` in rooted_or_relative_path_prefix
so that we optionally eat everything before a variable `$VAR/`.
2026-02-11 09:34:52 +01:00
Ben Kircher
af643a1a21 url: fix $-numeric character matches
Strings like

    $10/$20

Should not match.

This commit fixes this by narrowing `\w` after `$` to `[A-Za-z_]` which
is— according to Google Gemini— what environment variables can start
with.
2026-02-11 09:34:52 +01:00
Ben Kircher
0f904d92e0 url: fix mid-string dot partial matches
A string like

    foo.local/share

should match fully, not partially.

This commit fixes this by moving `dotted_path_lookahead` before
`bare_relative_path_prefix` so the dot-check scans the entire match
rather than only the text after it.
2026-02-11 09:34:52 +01:00
Ben Kircher
d8eb89f384 url: fix matching ~, $VAR, .directory/
Related to #1972

This commit adds three new alternatives for
`rooted_or_relative_path_prefix`:

- `~/`
- `$VAR` and
- `.local/`, `.config/` etc. for dot-prefixed directory names
2026-02-11 09:34:52 +01:00
Ben Kircher
72a894b13b url: remove , from path_chars
Related to #1972

Fixes an issue when paths have embedded comma, e.g.:

    shared/src/foo/SomeItem.m:12, shared/src/

with path_chars greedily consuming the rest of the string.

Now file path matching stops at comma. Scheme URLs are unchanged and
still using the comma.
2026-02-11 09:34:52 +01:00
Ben Kircher
c6e0de0bae url: carefully extend test cases
Extend existing test cases with `~`, `$VAR`, and bare .-prefixed paths
and embedded `,` comma handling.

See following issue comments:

- https://github.com/ghostty-org/ghostty/pull/10570#issuecomment-3853842036
- https://github.com/ghostty-org/ghostty/issues/1972#issuecomment-3859329233
- https://github.com/ghostty-org/ghostty/issues/1972#issuecomment-3857881196
2026-02-11 09:34:52 +01:00
Ben Kircher
f38366b5dc url: update top-level comment 2026-02-11 09:34:52 +01:00
Ben Kircher
16a076bd7f url: refactor regex into documented branches
Break up the big monolithic URL and path regex into named sub-pattern
constants and compose the final expression from three commented
branches:

- URLs with a scheme
- absolute or dot-relative paths
- bare relative paths

This commit only breaks up the regex. It keeps the existing matching
behavior unchanged.
2026-02-11 09:34:52 +01:00
Ben Kircher
6c0a17cccf Fix clicking bare relative file paths
Related to #1972

The URL regex for file path detection requires paths to start with
`../`, `./`, or `/`. For bare relative paths like
`"src/config/url.zig"`, the regex could only match starting at the first
`/`, producing `"/config/url.zig"` as a result — always dropping the
first part of the path.

Fix: added a third top-level alternative to the regex. This matches bare
relative paths where:

1. The first component is word characters (possibly with dots/dashes):
   `[\w][\w\-.]*\/`
2. The remaining path must contain a dot (via positive lookahead) — this
   requires a file extension to avoid false positives on text like
   input/output
3. Add a `(?<!\w)\/` instead of `\/` in the existing prefix group — the
   standalone `/` prefix now requires that `/` is not preceded by a word
   character. This prevents `"input/output"` from falsely matching
   `"/output"`

Test cases added:
- src/config/url.zig → matches fully
- app/folder/file.rb:1 → matches with line number
- modified:   src/config/url.zig → matches only the path part
- lib/ghostty/terminal.zig:42:10 → matches with line:col
- some-pkg/src/file.txt more text → stops before trailing text
- input/output and foo/bar → correctly do not match (no file extension)

The issue was nailed down here:
https://github.com/ghostty-org/ghostty/issues/1972#issuecomment-3845717672
2026-02-04 15:17:46 +01:00
Elad Kaplan
24413a9a24 Add a description to the test section comment 2025-12-16 10:17:54 +02:00
Elad Kaplan
32395fd838 Fix cmd-click opening of relative/local paths 2025-12-16 10:09:07 +02:00
Weizhao Ouyang
528814da79 url: restrict file paths regex to one slash
This restricts the valid path prefixes to prevent false matches caused
by literal dot.

Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
2025-05-14 23:20:09 +08:00
Mitchell Hashimoto
4d0bf303c6 ci: zig fmt check
This adds a CI test to ensure that all Zig files are properly formatted.
This avoids unrelated diff noise in future PRs.
2025-03-18 13:58:49 -07:00
Bryan Lee
c8d5b2da45 Add IPv6 URL pattern support with comprehensive test cases
- Add IPv6 URL pattern matching to support URLs like http://[::]:8000/
- Separate IPv6 URL pattern from main regex for better maintainability
- Add extensive test cases covering:
  - Basic IPv6 URLs with ports
  - URLs with paths and query parameters
  - Compressed IPv6 forms
  - Link-local and multicast addresses
  - Mixed scenarios and markdown contexts
2025-01-07 14:54:16 +08:00
Mustaque Ahmed
85743aebd5 feat: add support for file paths starts with ../ ./ and /
To implement this I extended the existing regex variable in the `src/config` dir. In a few test cases, extra space is added intentionally to verify we don't include space in the URL as it looks & feels odd.
2025-01-07 01:13:29 +05:30
Vincent Prigent
96bda270a2 Add two edge cases to the url regex 2024-11-22 22:57:45 +13:00
Erlend Lind Madsen
e3881c4ffc avoid escape characters by using a multiline string
lets concat url_scheme in combo with a multiline (thanks @qwerasd205)

regex: url_scheme -> url_schemes
2024-08-28 23:13:13 +02:00
Łukasz Niemier
f9be02a20f chore: clean up typos 2024-08-05 13:56:57 +02:00
Erlend Lind Madsen
c418ae577c url: add missing rarer (all) characters allowed in URL 2024-02-02 04:59:13 +01:00
Erlend Lind Madsen
823aedbb88 url: add missing url-scheme tests 2024-02-02 03:17:24 +01:00
Erlend Lind Madsen
a3e2d9d250 url: sort url schemes by most-used 2024-02-02 02:59:55 +01:00
Erlend Lind Madsen
ab8d5e261a url: support dash '-' in urls 2024-02-02 02:45:48 +01:00
Erlend Lind Madsen
4475f5b9c5 url/Link: simplify regex, remove 'find_longest' param and add new tests 2024-02-02 01:23:39 +01:00
Selman Kayrancioglu
9348561bc7 config/url: exclude trailing single quotes 2024-01-27 21:59:37 +03:00
Caleb Spare
ae94af37c0 config: improve link matching for URLs ending in . or )
Fixes #1098
2023-12-16 17:34:38 -08:00
Mitchell Hashimoto
5db002cb12 renderer/metal: underline urls 2023-11-29 15:30:21 -08:00