Skip to content

Commit

Permalink
Merge pull request #23529 from oleiman/sr/core-7738/weird-url-decode
Browse files Browse the repository at this point in the history
CORE-7738: pp/httpd: Remove extra decode on path param get
  • Loading branch information
oleiman authored Sep 27, 2024
2 parents 5f6970b + bcab3ff commit 51f87da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/v/pandaproxy/parsing/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,22 @@ T header(const ss::http::request& req, const ss::sstring& name) {
template<typename T>
T request_param(const ss::http::request& req, const ss::sstring& name) {
const auto& param{req.get_path_param(name)};
ss::sstring value;
if (!ss::http::internal::url_decode(param, value)) {
throw error(
error_code::invalid_param,
fmt::format("Invalid parameter '{}' got '{}'", name, param));
if (param.empty()) [[unlikely]] {
// either the param wasn't present or URL decoding failed
try {
const auto& p = req.param.at(name);
if (p.size() > 1) {
// we got something more than the leading '/', so URL decoding
// must have failed
throw error(
error_code::invalid_param,
fmt::format("Invalid parameter '{}' got '{}'", name, p));
}
} catch (const std::out_of_range& e) {
std::ignore = e;
}
}
return detail::parse_param<T>("parameter", name, value);
return detail::parse_param<T>("parameter", name, param);
}

template<typename T>
Expand Down
13 changes: 13 additions & 0 deletions tests/rptest/tests/schema_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,19 @@ def test_post_subjects_subject_versions(self):
result = result_raw.json()
# assert result["schema"] == json.dumps(schema_def)

self.logger.debug(
"Post schema 1 with escape chars in the subject name")
name = f"{topic}%25252fkey"
name_quoted = urllib.parse.quote(name)
result_raw = self._post_subjects_subject_versions(subject=name_quoted,
data=schema_1_data)
self.logger.warn(result_raw)
assert result_raw.status_code == requests.codes.ok
result_raw = self._get_subjects_subject_versions(subject=name_quoted)
assert result_raw.status_code == requests.codes.ok
subjs = self._get_subjects().json()
assert name in subjs, f"Expected '{name}' in subjects response, got {json.dumps(subjs, indent=1)}"

@cluster(num_nodes=3)
def test_post_subjects_subject_versions_version_many(self):
"""
Expand Down

0 comments on commit 51f87da

Please sign in to comment.