Skip to content

Commit

Permalink
fix url_pattern_component constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Dec 31, 2024
1 parent 5ced1da commit f76e3ee
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/ada/url_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ class url_pattern_component {

// This function explicitly takes a std::string because it is moved.
// To avoid unnecessary copy, move each value while calling the constructor.
url_pattern_component(std::string_view new_pattern, std::regex&& new_regexp,
url_pattern_component(std::string&& new_pattern, std::regex&& new_regexp,
std::regex_constants::syntax_option_type new_flags,
std::vector<std::string>&& new_group_name_list,
bool new_has_regexp_groups)
: regexp(new_regexp),
: regexp(std::move(new_regexp)),
pattern(std::move(new_pattern)),
flags(new_flags),
group_name_list(new_group_name_list),
Expand Down
36 changes: 36 additions & 0 deletions pbcopy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/include/ada/url_pattern-inl.h b/include/ada/url_pattern-inl.h
index c7c04a06..6da583e9 100644
--- a/include/ada/url_pattern-inl.h
+++ b/include/ada/url_pattern-inl.h
@@ -41,7 +41,7 @@ url_pattern_component::create_component_match_result(
// Let value be Get(execResult, ToString(index)).
// Set groups[name] to value.
result.groups.insert({
- group_name_list[index - 1],
+ "",
exec_result[index].str(),
});
}
diff --git a/include/ada/url_pattern.h b/include/ada/url_pattern.h
index 13466dd6..7aa41a57 100644
--- a/include/ada/url_pattern.h
+++ b/include/ada/url_pattern.h
@@ -203,9 +203,8 @@ class url_pattern_component {
std::vector<std::string>&& new_group_name_list,
bool new_has_regexp_groups)
: regexp(new_regexp),
- pattern(std::move(new_pattern)),
+ pattern(new_pattern),
flags(new_flags),
- group_name_list(new_group_name_list),
has_regexp_groups(new_has_regexp_groups) {}

// @see https://urlpattern.spec.whatwg.org/#compile-a-component
@@ -223,7 +222,6 @@ class url_pattern_component {
std::regex regexp{};
std::string pattern{};
std::regex_constants::syntax_option_type flags = std::regex::ECMAScript;
- std::vector<std::string> group_name_list{};
bool has_regexp_groups = false;
};

2 changes: 1 addition & 1 deletion src/url_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ url_pattern_component::compile(std::string_view input, F encoding_callback,
// Return a new component whose pattern string is pattern string, regular
// expression is regular expression, group name list is name list, and has
// regexp groups is has regexp groups.
return url_pattern_component(pattern_string, std::move(regular_expression),
return url_pattern_component(std::move(pattern_string), std::move(regular_expression),
flags, std::move(name_list), has_regexp_groups);
}

Expand Down

0 comments on commit f76e3ee

Please sign in to comment.