mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
AK: Make debugging URLParser easier
This patch adds a state_name method to URLParser to convert a state to a string. With this, the debugging statements now display the state names. Furthermore, this fixes a bug where non-ASCII code points were formatted as characters, which fails an assertion in the formatting system.
This commit is contained in:
parent
99d5555134
commit
97425c7dfb
2 changed files with 45 additions and 24 deletions
|
@ -228,10 +228,12 @@ URL URLParser::parse(Badge<URL>, StringView const& raw_input, URL const* base_ur
|
||||||
code_point = *iterator;
|
code_point = *iterator;
|
||||||
|
|
||||||
if constexpr (URL_PARSER_DEBUG) {
|
if constexpr (URL_PARSER_DEBUG) {
|
||||||
if (code_point)
|
if (!code_point)
|
||||||
dbgln("URLParser::parse: State {:2d} with code point '{:c}' (U+{:04X}).", (int)state, code_point, code_point);
|
dbgln("URLParser::parse: {} state with EOF.", state_name(state));
|
||||||
|
else if (is_ascii_printable(code_point))
|
||||||
|
dbgln("URLParser::parse: {} state with code point U+{:04X} ({:c}).", state_name(state), code_point, code_point);
|
||||||
else
|
else
|
||||||
dbgln("URLParser::parse: State {:2d} with code point EOF (U+0000).", (int)state);
|
dbgln("URLParser::parse: {} state with code point U+{:04X}.", state_name(state), code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
|
@ -12,38 +12,57 @@
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
#define ENUMERATE_STATES \
|
||||||
|
STATE(SchemeStart) \
|
||||||
|
STATE(Scheme) \
|
||||||
|
STATE(NoScheme) \
|
||||||
|
STATE(SpecialRelativeOrAuthority) \
|
||||||
|
STATE(PathOrAuthority) \
|
||||||
|
STATE(Relative) \
|
||||||
|
STATE(RelativeSlash) \
|
||||||
|
STATE(SpecialAuthoritySlashes) \
|
||||||
|
STATE(SpecialAuthorityIgnoreSlashes) \
|
||||||
|
STATE(Authority) \
|
||||||
|
STATE(Host) \
|
||||||
|
STATE(Hostname) \
|
||||||
|
STATE(Port) \
|
||||||
|
STATE(File) \
|
||||||
|
STATE(FileSlash) \
|
||||||
|
STATE(FileHost) \
|
||||||
|
STATE(PathStart) \
|
||||||
|
STATE(Path) \
|
||||||
|
STATE(CannotBeABaseUrlPath) \
|
||||||
|
STATE(Query) \
|
||||||
|
STATE(Fragment)
|
||||||
|
|
||||||
class URLParser {
|
class URLParser {
|
||||||
public:
|
public:
|
||||||
enum class State {
|
enum class State {
|
||||||
SchemeStart,
|
#define STATE(state) state,
|
||||||
Scheme,
|
ENUMERATE_STATES
|
||||||
NoScheme,
|
#undef STATE
|
||||||
SpecialRelativeOrAuthority,
|
|
||||||
PathOrAuthority,
|
|
||||||
Relative,
|
|
||||||
RelativeSlash,
|
|
||||||
SpecialAuthoritySlashes,
|
|
||||||
SpecialAuthorityIgnoreSlashes,
|
|
||||||
Authority,
|
|
||||||
Host,
|
|
||||||
Hostname,
|
|
||||||
Port,
|
|
||||||
File,
|
|
||||||
FileSlash,
|
|
||||||
FileHost,
|
|
||||||
PathStart,
|
|
||||||
Path,
|
|
||||||
CannotBeABaseUrlPath,
|
|
||||||
Query,
|
|
||||||
Fragment
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char const* state_name(State const& state)
|
||||||
|
{
|
||||||
|
switch (state) {
|
||||||
|
#define STATE(state) \
|
||||||
|
case State::state: \
|
||||||
|
return #state;
|
||||||
|
ENUMERATE_STATES
|
||||||
|
#undef STATE
|
||||||
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
static URL parse(Badge<URL>, StringView const& input, URL const* base_url = nullptr);
|
static URL parse(Badge<URL>, StringView const& input, URL const* base_url = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Optional<URL> parse_data_url(StringView const& raw_input);
|
static Optional<URL> parse_data_url(StringView const& raw_input);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#undef ENUMERATE_STATES
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::URLParser;
|
using AK::URLParser;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue