-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LSP: Fixes URL decoding incoming file names. #13473
Conversation
b2bb4b0
to
92d34ad
Compare
b70e77c
to
4d2c844
Compare
4d2c844
to
a72c628
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see at least one test with a full url that is also using /
This comment was marked as resolved.
This comment was marked as resolved.
e9fc513
to
b298001
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, but could use some small tweaks.
@@ -20,6 +21,7 @@ Important Bugfixes: | |||
|
|||
Compiler Features: | |||
* Code Generator: More efficient overflow checks for multiplication. | |||
* Yul Optimizer: Simplify the starting offset of zero-length operations to zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems out of place in this PR.
@@ -7,6 +7,7 @@ Compiler Features: | |||
* Commandline Interface: Add `--no-cbor-metadata` that skips CBOR metadata from getting appended at the end of the bytecode. | |||
* Standard JSON: Add a boolean field `settings.metadata.appendCBOR` that skips CBOR metadata from getting appended at the end of the bytecode. | |||
* Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string. | |||
* Language Server: Fixes URL decoding of incoming file names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was initially confused as to why file names would need URL-decoding. I think it would be better to say that we're decoding the file://
URLs.
* Language Server: Fixes URL decoding of incoming file names. | |
* Language Server: Properly URL-decode the `file://` URIs coming from the client and encode the URIs coming out of by the server. |
I'd also say it's a bugfix rather than a feature :)
target_link_libraries(solutil PUBLIC jsoncpp Boost::boost Boost::filesystem Boost::system range-v3) | ||
target_link_libraries(solutil PUBLIC jsoncpp Boost::boost Boost::filesystem Boost::system range-v3 fmt::fmt-header-only) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the URL-encoding helpers are things I'd put in a separate commit. They should stand out as its own thing in history.
/// Decodes a URI with respect to %XX notation. | ||
/// No URI-validity verification is performed but simply the URI decoded into non-escaping characters. | ||
std::string decodeURI(std::string const& _uri); | ||
|
||
/// Encodes a string into a URI conform notation. | ||
std::string encodeURI(std::string const& _uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that these don't have to be URIs (it works for arbitrary strings), I'd call it something like urlEncode()
and urlDecode()
(or even urlencode()
and urldecode()
). I associate the term "urlencoding" specifically with this kind of encoding while "encoding an URI" could mean any encoding. I would probably look for the former I wanted to find it.
/// Decodes a URI with respect to %XX notation. | ||
/// No URI-validity verification is performed but simply the URI decoded into non-escaping characters. | ||
std::string decodeURI(std::string const& _uri); | ||
|
||
/// Encodes a string into a URI conform notation. | ||
std::string encodeURI(std::string const& _uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Decodes a URI with respect to %XX notation. | |
/// No URI-validity verification is performed but simply the URI decoded into non-escaping characters. | |
std::string decodeURI(std::string const& _uri); | |
/// Encodes a string into a URI conform notation. | |
std::string encodeURI(std::string const& _uri); | |
/// Decodes a percent-encoded string (i.e. the %XX notation). | |
/// No URI-validity verification is performed but simply the URI decoded into non-escaping characters. | |
std::string decodeURI(std::string const& _uri); | |
/// Percent-encodes a string. | |
/// Note that `:` and `/` are preserved, which means that the function will not mangle the `protocol://` | |
/// prefix in URLs. | |
std::string encodeURI(std::string const& _uri); |
BOOST_CHECK_EQUAL(util::decodeURI(""), ""); | ||
BOOST_CHECK_EQUAL(util::decodeURI(""), ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate test.
{ | ||
BOOST_CHECK_EQUAL(util::decodeURI(""), ""); | ||
BOOST_CHECK_EQUAL(util::decodeURI(""), ""); | ||
BOOST_CHECK_EQUAL(util::decodeURI(" ")," "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BOOST_CHECK_EQUAL(util::decodeURI(" ")," "); | |
BOOST_CHECK_EQUAL(util::decodeURI(" "), " "); |
// Decoding failure cases (there's not really a standard for that). | ||
BOOST_CHECK_EQUAL(util::decodeURI("%"), ""); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%ZZ"), "ZZ"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%7Ge"), "7Ge"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%2F%2%2F"), "/2/"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%1G/%7G/%FG"), "1G/7G/FG"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to handle these as errors? Having %
silently disappear from the end of a string when you pass in something not encoded by accident does not sound like the nicest behavior.
BOOST_CHECK_EQUAL(util::decodeURI("%25"), "%"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("Hello%20World."), "Hello World."); | ||
BOOST_CHECK_EQUAL(util::decodeURI("Hello World."), "Hello World."); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%01%02%7F"), "\x01\x02\x7F"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("C%3A%5Creadme.md"), "C:\\readme.md"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("C:/readme.md"), "C:/readme.md"); | ||
|
||
// Decoding failure cases (there's not really a standard for that). | ||
BOOST_CHECK_EQUAL(util::decodeURI("%"), ""); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%ZZ"), "ZZ"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%7Ge"), "7Ge"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%2F%2%2F"), "/2/"); | ||
BOOST_CHECK_EQUAL(util::decodeURI("%1G/%7G/%FG"), "1G/7G/FG"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a few more?
- A Windows path with a
file://
prefix. %😃
%Z
@@ -747,7 +752,9 @@ def run_testcase(self, testcase: TestParser.RequestAndResponse): | |||
if isinstance(actualResponseJson["result"], list): | |||
for result in actualResponseJson["result"]: | |||
if "uri" in result: | |||
result["uri"] = result["uri"].replace(self.suite.project_root_uri + "/" + self.sub_dir + "/", "") | |||
result["uri"] = decodeURI(result["uri"]).replace( | |||
self.suite.project_root_uri + "/" + self.sub_dir + "/", "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.suite.project_root_uri + "/" + self.sub_dir + "/", "" | |
self.suite.project_root_uri + "/" + self.sub_dir + "/", | |
"" |
b298001
to
a2de5d4
Compare
This pull request is stale because it has been open for 14 days with no activity. |
This fixes #13035.
On Windows platform, it is much more likely to hit, as we did not URL decode the incoming URL, and thus, the files (nor the base path, if specified as
rootUri
) could not be opened nor traversed.Checklist