mirror of
https://github.com/walles/moar.git
synced 2024-11-22 21:50:43 +03:00
Accept \ characters in URLs
Generated by some software on Windows, also accepted by less. We should accept them for compatibility reasons. Fixes #244.
This commit is contained in:
parent
6d3bf3dfd4
commit
4930d0aed3
@ -208,9 +208,12 @@ func (s *styledStringSplitter) handleOsc(sequence string) error {
|
||||
|
||||
// We just got ESC]8; and should now read the URL. URLs end with ASCII 7 BEL or ESC \.
|
||||
func (s *styledStringSplitter) handleURL() error {
|
||||
// Ref: https://github.com/walles/moar/issues/244#issuecomment-2350908401
|
||||
const windowsURLChars = `\`
|
||||
|
||||
// Valid URL characters.
|
||||
// Ref: https://stackoverflow.com/a/1547940/473672
|
||||
const validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;="
|
||||
const validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=" + windowsURLChars
|
||||
|
||||
// Points to right after "ESC]8;"
|
||||
urlStartIndex := s.nextByteIndex
|
||||
|
@ -68,3 +68,16 @@ func TestColonColors(t *testing.T) {
|
||||
assert.Equal(t, "hello", styledStrings[0].String)
|
||||
assert.Equal(t, twin.StyleDefault.WithForeground(twin.NewColor256(238)), styledStrings[0].Style)
|
||||
}
|
||||
|
||||
// Test handling of URLs with backslashes in them. Generated by some software on
|
||||
// Windows, also accepted by less.
|
||||
//
|
||||
// Ref: https://github.com/walles/moar/issues/244
|
||||
func TestWindowsURL(t *testing.T) {
|
||||
windowsPath := `src\detection\cpu\cpu_bsd.c`
|
||||
windowsCwd := `C:\msys64\home\zhang\fastfetch\src\detection\cpu\cpu_bsd.c`
|
||||
styledStrings, trailer := collectStyledStrings("\x1b]8;;vscode://file/" + windowsCwd + "\\" + windowsPath + "\x07" + windowsPath)
|
||||
assert.Equal(t, twin.StyleDefault, trailer)
|
||||
assert.Equal(t, 1, len(styledStrings))
|
||||
assert.Equal(t, windowsPath, styledStrings[0].String)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user