Skip to content

Commit

Permalink
Change url.origin() to serialize origin as ASCII
Browse files Browse the repository at this point in the history
Follows whatwg/url#311

Rename previous origin serializer to origin_unicode()
  • Loading branch information
rmisev committed May 19, 2017
1 parent 41eda78 commit f92cb5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ class url {
}

// ASCII serialized origin
std::string origin_ascii() const;
// Unicode serialized origin in utf-8
std::string origin() const;
// Unicode serialized origin in utf-8
std::string origin_unicode() const;

std::string protocol() const {
return std::string(norm_url_.data(), part_end_[SCHEME] ? part_end_[SCHEME] + 1 : 0);
Expand Down Expand Up @@ -878,7 +878,7 @@ inline bool is_special_authority_end_char(CharT c) {

// ASCII serialization of an origin
// https://html.spec.whatwg.org/multipage/browsers.html#ascii-serialisation-of-an-origin
inline std::string url::origin_ascii() const {
inline std::string url::origin() const {
if (is_special_scheme()) {
if (is_file_scheme())
return "null"; // opaque origin
Expand All @@ -890,14 +890,14 @@ inline std::string url::origin_ascii() const {
} else if (get_part_view(SCHEME).equal({ "blob", 4 })) {
url u;
if (u.parse(get_part_view(PATH), nullptr))
return u.origin_ascii();
return u.origin();
}
return "null"; // opaque origin
}

// Unicode serialization of an origin
// https://html.spec.whatwg.org/multipage/browsers.html#unicode-serialisation-of-an-origin
inline std::string url::origin() const {
inline std::string url::origin_unicode() const {
if (is_special_scheme()) {
if (is_file_scheme())
return "null"; // opaque origin
Expand All @@ -920,7 +920,7 @@ inline std::string url::origin() const {
} else if (get_part_view(SCHEME).equal({ "blob", 4 })) {
url u;
if (u.parse(get_part_view(PATH), nullptr))
return u.origin();
return u.origin_unicode();
}
return "null"; // opaque origin
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void cout_url(const whatwg::url& url) {
std::wcout << "HREF: " << to_wstr(url.href()) << "\n";

// origin
std::wcout << "origin: " << to_wstr(url.origin_ascii()) << "\n";
std::wcout << "origin: " << to_wstr(url.origin()) << "\n";

// print parts
for (int part = whatwg::url::SCHEME; part < whatwg::url::PART_COUNT; part++) {
Expand Down

0 comments on commit f92cb5d

Please sign in to comment.