Skip to content

Commit

Permalink
File state fix to correctly deal with lack of base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Feb 6, 2017
1 parent 9042a18 commit 5a04f57
Showing 1 changed file with 39 additions and 43 deletions.
82 changes: 39 additions & 43 deletions url.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,55 +998,51 @@ inline bool url_parser::url_parse(url_serializer& urls, const CharT* first, cons
if (state == file_state) {
if (!urls.is_file_scheme())
urls.set_scheme({ "file", 4 });
if (pointer == last) {
// EOF code point
// EOF ==> 0 ==> default:
switch (pointer != last ? *pointer : 0) {
case '\\':
// TODO-WARN: syntax violation
case '/':
state = file_slash_state;
pointer++;
break;

default:
if (base && base->is_file_scheme()) {
// set url’s host to base’s host, url’s path to base’s path, and url’s query to base’s query
urls.append_parts(*base, url::HOST, url::QUERY);
}
return true; // EOF
} else {
const CharT ch = *(pointer++);
switch (ch) {
case '\\':
// TODO-WARN: syntax violation
case '/':
state = file_slash_state;
break;
case '?':
if (base && base->is_file_scheme()) {
// set url’s host to base’s host, url’s path to base’s path, url’s query to the empty string
urls.append_parts(*base, url::HOST, url::PATH);
state = query_state; // sets query to the empty string
} else {
//TODO: čia neaišku ar ignoruoti ch ir cikle imti kitą ar:
state = query_state; // sets query to the empty string
}
break;
case '#':
if (base && base->is_file_scheme()) {
// set url’s host to base’s host, url’s path to base’s path, url’s query to base’s query, url’s fragment to the empty string
if (pointer == last) {
// EOF code point
// Set url's host to base's host, url's path to base's path, and url's query to base's query
urls.append_parts(*base, url::HOST, url::QUERY);
state = fragment_state; // sets fragment to the empty string
return true; // EOF
} else {
//TODO: čia neaišku ar ignoruoti ch ir cikle imti kitą ar:
state = fragment_state; // sets fragment to the empty string
}
break;
default:
if (base && base->is_file_scheme()) {
if (pointer + 1 == last // remaining consists of one code point
|| (pointer + 1 < last && !is_Windows_drive(ch, pointer[0]))
|| (pointer + 2 < last && !is_special_authority_end_char(pointer[1]))
) {
// set url’s host to base’s host, url’s path to base’s path, and then shorten url’s path
urls.append_parts(*base, url::HOST, url::PATH, &url::get_shorten_path);
// Note: This is a (platform-independent) Windows drive letter quirk.
const CharT ch = *(pointer++);
switch (ch) {
case '?':
// Set url's host to base's host, url's path to base's path, url's query to the empty string
urls.append_parts(*base, url::HOST, url::PATH);
state = query_state; // sets query to the empty string
break;
case '#':
// Set url's host to base's host, url's path to base's path, url's query to base's query, url's fragment to the empty string
urls.append_parts(*base, url::HOST, url::QUERY);
state = fragment_state; // sets fragment to the empty string
break;
default:
if (pointer + 1 == last // remaining consists of one code point
|| (pointer + 1 < last && !is_Windows_drive(ch, pointer[0]))
|| (pointer + 2 < last && !is_special_authority_end_char(pointer[1]))
) {
// set url’s host to base’s host, url’s path to base’s path, and then shorten url’s path
urls.append_parts(*base, url::HOST, url::PATH, &url::get_shorten_path);
// Note: This is a (platform-independent) Windows drive letter quirk.
}
//else // TODO-WARN: syntax violation
state = path_state;
pointer--;
}
// else // TODO-WARN: syntax violation
}
} else {
state = path_state;
pointer--;
}
}
}
Expand Down

0 comments on commit 5a04f57

Please sign in to comment.