fix: avoid path trailing slash stripped in older os versions by ACTCD · Pull Request #695 · quoid/userscripts · GitHub
Skip to content

fix: avoid path trailing slash stripped in older os versions#695

Merged
ACTCD merged 4 commits into
mainfrom
issue/694/path-trailing-stripped-in-older-os-versions
Aug 26, 2024
Merged

fix: avoid path trailing slash stripped in older os versions#695
ACTCD merged 4 commits into
mainfrom
issue/694/path-trailing-stripped-in-older-os-versions

Conversation

@ACTCD

@ACTCD ACTCD commented Aug 23, 2024

Copy link
Copy Markdown
Collaborator

fix #694

Thanks to @esterTion for reporting, debugging and finding this issue.

Co-authored-by: esterTion <lcz970@126.com>
@ACTCD ACTCD requested a review from quoid August 23, 2024 15:35
@esterTion

Copy link
Copy Markdown
Contributor

@ACTCD

ACTCD commented Aug 24, 2024

Copy link
Copy Markdown
Collaborator Author

@esterTion Really? I didn't reproduce that. But I can't have tested it on a really old system.

If the path has a trailing slash, it is stripped. https://developer.apple.com/documentation/foundation/nsurl/1408809-path

Actually looking at the documentation for Swift URL, it doesn't mention this at all, and it doesn't explicitly mention that it uses NSURL internally.
https://developer.apple.com/documentation/foundation/url/1779812-path

We're not using NSURL but just Swift URL, which is why I didn't notice this in the first place.

And I remember doing tests for both code paths that passed, I don't know why it's failing now.

@ACTCD

ACTCD commented Aug 24, 2024

Copy link
Copy Markdown
Collaborator Author

nsurl is actually weird, i think http://example.com/dir/?query will have path of /dir?query

@esterTion I just tested and neither NSURL nor URL can reproduce this. Of course, I still can't test it in a really old OS.

import Foundation

let nsurl = NSURL(string: "http://example.com/dir/?query")!
let url = URL(string: "http://example.com/dir/?query")!

print(nsurl.path)
print(url.path)

test

@esterTion

esterTion commented Aug 25, 2024

Copy link
Copy Markdown
Contributor

sry posted on wrong thread

#694 (comment)

图片
This is on macOS 10.15.3

I now think this should be considered a platform bug

@ACTCD

ACTCD commented Aug 25, 2024

Copy link
Copy Markdown
Collaborator Author

@esterTion

Where is your breakpoint? In the match(_:_:) func?

func match(_ url: String, _ matchPattern: String) -> Bool {
guard
let parts = jsLikeURL(url),
let ptcl = parts["protocol"],
let host = parts["hostname"],
var path = parts["pathname"]
else {
logger?.error("\(#function, privacy: .public) - invalid url \(url, privacy: .public)")
return false
}
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns#path
// The value for the path matches against the string which is the URL path plus the URL query string
if let search = parts["search"], search.count > 0 {
path += search
}

Then what you see may be the path that has been processed by us and is only used for subsequent matching.

Please try running just the code I posted above in the Playground (outside the project).

@esterTion

esterTion commented Aug 26, 2024

Copy link
Copy Markdown
Contributor

@ACTCD ACTCD merged commit fc65c23 into main Aug 26, 2024
@ACTCD ACTCD deleted the issue/694/path-trailing-stripped-in-older-os-versions branch August 26, 2024 03:52
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.

[Bug] @match wrong behaivour after v1.5.0 update

3 participants