Skip to content

Commit

Permalink
Don't allow empty namespace names
Browse files Browse the repository at this point in the history
For example, an attribute :class was parsed as having an empty
namespace, with local name "class". It is now parsed as no namespace,
local name ":class". Per the namespace spec at

  https://www.w3.org/TR/xml-names/#iri-use

> The empty string, though it is a legal URI reference, cannot be used
> as a namespace name.

Fixes aantron/lambdasoup#39.
  • Loading branch information
aantron committed Jul 2, 2021
1 parent ddc5898 commit 359f336
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/namespace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct
let parse qualified_name =
try
let colon_index = String.index qualified_name ':' in
if colon_index = 0 then
raise Not_found;
let prefix = String.sub qualified_name 0 colon_index in
let suffix =
String.sub qualified_name
Expand Down
11 changes: 11 additions & 0 deletions test/test_html_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,17 @@ let tests = [
10, 13, S `End_element;
10, 13, S `End_element]);

("html.parser.attributes" >:: fun _ ->
expect "<div :class='foo'></div>"
[ 1, 1, S (start_element "html");
1, 1, S (start_element "head");
1, 1, S `End_element;
1, 1, S (start_element "body");
1, 1, S (`Start_element ((html_ns, "div"), [(("", ":class"), "foo")]));
1, 19, S `End_element;
1, 25, S `End_element;
1, 25, S `End_element]);

("html.parser.links" >:: fun _ ->
expect
{|<a href="foo.com?bar=on&acte=123">foo</a>|}
Expand Down

0 comments on commit 359f336

Please sign in to comment.