nokogiri 1.12.5 → 1.14.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +41 -0
  3. data/LICENSE-DEPENDENCIES.md +830 -509
  4. data/LICENSE.md +1 -1
  5. data/README.md +23 -14
  6. data/bin/nokogiri +63 -50
  7. data/dependencies.yml +33 -66
  8. data/ext/nokogiri/extconf.rb +159 -63
  9. data/ext/nokogiri/gumbo.c +21 -11
  10. data/ext/nokogiri/html4_document.c +2 -2
  11. data/ext/nokogiri/html4_element_description.c +1 -1
  12. data/ext/nokogiri/html4_entity_lookup.c +2 -2
  13. data/ext/nokogiri/html4_sax_parser_context.c +3 -9
  14. data/ext/nokogiri/html4_sax_push_parser.c +1 -1
  15. data/ext/nokogiri/nokogiri.c +38 -51
  16. data/ext/nokogiri/nokogiri.h +26 -14
  17. data/ext/nokogiri/test_global_handlers.c +1 -1
  18. data/ext/nokogiri/xml_attr.c +3 -3
  19. data/ext/nokogiri/xml_attribute_decl.c +5 -5
  20. data/ext/nokogiri/xml_cdata.c +3 -3
  21. data/ext/nokogiri/xml_comment.c +1 -1
  22. data/ext/nokogiri/xml_document.c +53 -44
  23. data/ext/nokogiri/xml_document_fragment.c +1 -3
  24. data/ext/nokogiri/xml_dtd.c +11 -11
  25. data/ext/nokogiri/xml_element_content.c +3 -3
  26. data/ext/nokogiri/xml_element_decl.c +5 -5
  27. data/ext/nokogiri/xml_encoding_handler.c +28 -14
  28. data/ext/nokogiri/xml_entity_decl.c +6 -6
  29. data/ext/nokogiri/xml_entity_reference.c +1 -1
  30. data/ext/nokogiri/xml_namespace.c +80 -14
  31. data/ext/nokogiri/xml_node.c +982 -396
  32. data/ext/nokogiri/xml_node_set.c +4 -6
  33. data/ext/nokogiri/xml_processing_instruction.c +1 -1
  34. data/ext/nokogiri/xml_reader.c +133 -32
  35. data/ext/nokogiri/xml_relax_ng.c +1 -3
  36. data/ext/nokogiri/xml_sax_parser.c +23 -17
  37. data/ext/nokogiri/xml_sax_parser_context.c +11 -9
  38. data/ext/nokogiri/xml_sax_push_parser.c +1 -3
  39. data/ext/nokogiri/xml_schema.c +4 -6
  40. data/ext/nokogiri/xml_syntax_error.c +1 -1
  41. data/ext/nokogiri/xml_text.c +2 -2
  42. data/ext/nokogiri/xml_xpath_context.c +144 -114
  43. data/ext/nokogiri/xslt_stylesheet.c +122 -23
  44. data/gumbo-parser/Makefile +10 -0
  45. data/gumbo-parser/src/attribute.h +1 -1
  46. data/gumbo-parser/src/error.c +2 -2
  47. data/gumbo-parser/src/error.h +1 -1
  48. data/gumbo-parser/src/foreign_attrs.c +2 -2
  49. data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
  50. data/gumbo-parser/src/parser.c +8 -16
  51. data/gumbo-parser/src/replacement.h +1 -1
  52. data/gumbo-parser/src/string_buffer.h +1 -1
  53. data/gumbo-parser/src/string_piece.c +1 -1
  54. data/gumbo-parser/src/svg_attrs.c +2 -2
  55. data/gumbo-parser/src/svg_tags.c +2 -2
  56. data/gumbo-parser/src/tag.c +2 -1
  57. data/gumbo-parser/src/tag_lookup.c +7 -7
  58. data/gumbo-parser/src/tag_lookup.gperf +1 -0
  59. data/gumbo-parser/src/tag_lookup.h +1 -1
  60. data/gumbo-parser/src/token_buffer.h +1 -1
  61. data/gumbo-parser/src/tokenizer.c +1 -1
  62. data/gumbo-parser/src/tokenizer.h +1 -1
  63. data/gumbo-parser/src/utf8.c +1 -1
  64. data/gumbo-parser/src/utf8.h +1 -1
  65. data/gumbo-parser/src/util.c +1 -3
  66. data/gumbo-parser/src/util.h +4 -0
  67. data/gumbo-parser/src/vector.h +1 -1
  68. data/lib/nokogiri/class_resolver.rb +67 -0
  69. data/lib/nokogiri/css/node.rb +9 -8
  70. data/lib/nokogiri/css/parser.rb +360 -341
  71. data/lib/nokogiri/css/parser.y +249 -244
  72. data/lib/nokogiri/css/parser_extras.rb +22 -20
  73. data/lib/nokogiri/css/syntax_error.rb +1 -0
  74. data/lib/nokogiri/css/tokenizer.rb +4 -3
  75. data/lib/nokogiri/css/tokenizer.rex +3 -2
  76. data/lib/nokogiri/css/xpath_visitor.rb +184 -85
  77. data/lib/nokogiri/css.rb +44 -6
  78. data/lib/nokogiri/decorators/slop.rb +8 -7
  79. data/lib/nokogiri/encoding_handler.rb +57 -0
  80. data/lib/nokogiri/extension.rb +4 -3
  81. data/lib/nokogiri/gumbo.rb +1 -0
  82. data/lib/nokogiri/html.rb +16 -10
  83. data/lib/nokogiri/html4/builder.rb +1 -0
  84. data/lib/nokogiri/html4/document.rb +56 -164
  85. data/lib/nokogiri/html4/document_fragment.rb +11 -7
  86. data/lib/nokogiri/html4/element_description.rb +1 -0
  87. data/lib/nokogiri/html4/element_description_defaults.rb +432 -532
  88. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  89. data/lib/nokogiri/html4/entity_lookup.rb +2 -1
  90. data/lib/nokogiri/html4/sax/parser.rb +5 -2
  91. data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
  92. data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
  93. data/lib/nokogiri/html4.rb +12 -5
  94. data/lib/nokogiri/html5/document.rb +126 -32
  95. data/lib/nokogiri/html5/document_fragment.rb +14 -4
  96. data/lib/nokogiri/html5/node.rb +12 -7
  97. data/lib/nokogiri/html5.rb +138 -222
  98. data/lib/nokogiri/jruby/dependencies.rb +2 -19
  99. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  100. data/lib/nokogiri/syntax_error.rb +1 -0
  101. data/lib/nokogiri/version/constant.rb +2 -1
  102. data/lib/nokogiri/version/info.rb +32 -24
  103. data/lib/nokogiri/version.rb +1 -0
  104. data/lib/nokogiri/xml/attr.rb +54 -3
  105. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  106. data/lib/nokogiri/xml/builder.rb +35 -33
  107. data/lib/nokogiri/xml/cdata.rb +2 -1
  108. data/lib/nokogiri/xml/character_data.rb +1 -0
  109. data/lib/nokogiri/xml/document.rb +232 -143
  110. data/lib/nokogiri/xml/document_fragment.rb +88 -42
  111. data/lib/nokogiri/xml/dtd.rb +3 -2
  112. data/lib/nokogiri/xml/element_content.rb +1 -0
  113. data/lib/nokogiri/xml/element_decl.rb +2 -1
  114. data/lib/nokogiri/xml/entity_decl.rb +3 -2
  115. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  116. data/lib/nokogiri/xml/namespace.rb +44 -0
  117. data/lib/nokogiri/xml/node/save_options.rb +14 -8
  118. data/lib/nokogiri/xml/node.rb +708 -383
  119. data/lib/nokogiri/xml/node_set.rb +134 -59
  120. data/lib/nokogiri/xml/notation.rb +12 -0
  121. data/lib/nokogiri/xml/parse_options.rb +140 -56
  122. data/lib/nokogiri/xml/pp/character_data.rb +8 -6
  123. data/lib/nokogiri/xml/pp/node.rb +26 -26
  124. data/lib/nokogiri/xml/pp.rb +1 -0
  125. data/lib/nokogiri/xml/processing_instruction.rb +3 -1
  126. data/lib/nokogiri/xml/reader.rb +20 -24
  127. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  128. data/lib/nokogiri/xml/sax/document.rb +20 -19
  129. data/lib/nokogiri/xml/sax/parser.rb +38 -36
  130. data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
  131. data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
  132. data/lib/nokogiri/xml/sax.rb +1 -0
  133. data/lib/nokogiri/xml/schema.rb +7 -6
  134. data/lib/nokogiri/xml/searchable.rb +93 -62
  135. data/lib/nokogiri/xml/syntax_error.rb +5 -4
  136. data/lib/nokogiri/xml/text.rb +1 -0
  137. data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
  138. data/lib/nokogiri/xml/xpath.rb +12 -0
  139. data/lib/nokogiri/xml/xpath_context.rb +2 -3
  140. data/lib/nokogiri/xml.rb +4 -3
  141. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  142. data/lib/nokogiri/xslt.rb +21 -13
  143. data/lib/nokogiri.rb +22 -27
  144. data/lib/xsd/xmlparser/nokogiri.rb +28 -25
  145. data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
  146. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2445 -1919
  147. data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
  148. data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
  149. metadata +20 -171
  150. data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
  151. data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
  152. data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -2511
  153. data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +0 -31
  154. data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +0 -19
  155. data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
  156. data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -24,7 +24,7 @@
24
24
  #include "ascii.h"
25
25
  #include "attribute.h"
26
26
  #include "error.h"
27
- #include "gumbo.h"
27
+ #include "nokogiri_gumbo.h"
28
28
  #include "insertion_mode.h"
29
29
  #include "macros.h"
30
30
  #include "parser.h"
@@ -537,7 +537,7 @@ static GumboInsertionMode get_current_template_insertion_mode (
537
537
  if (modes->length == 0) {
538
538
  return GUMBO_INSERTION_MODE_INITIAL;
539
539
  }
540
- return (GumboInsertionMode) modes->data[(modes->length - 1)];
540
+ return (GumboInsertionMode)(intptr_t) modes->data[(modes->length - 1)];
541
541
  }
542
542
 
543
543
  // Returns true if the specified token is either a start or end tag
@@ -2940,7 +2940,7 @@ static void handle_in_body(GumboParser* parser, GumboToken* token) {
2940
2940
  TAG(DETAILS), TAG(DIALOG), TAG(DIR), TAG(DIV), TAG(DL), TAG(FIELDSET),
2941
2941
  TAG(FIGCAPTION), TAG(FIGURE), TAG(FOOTER), TAG(HEADER), TAG(HGROUP),
2942
2942
  TAG(MAIN), TAG(MENU), TAG(NAV), TAG(OL), TAG(P), TAG(SECTION),
2943
- TAG(SUMMARY), TAG(UL)
2943
+ TAG(SUMMARY), TAG(UL), TAG(SEARCH)
2944
2944
  })
2945
2945
  ) {
2946
2946
  maybe_implicitly_close_p_tag(parser, token);
@@ -3018,7 +3018,7 @@ static void handle_in_body(GumboParser* parser, GumboToken* token) {
3018
3018
  TAG(CENTER), TAG(DETAILS), TAG(DIALOG), TAG(DIR), TAG(DIV), TAG(DL),
3019
3019
  TAG(FIELDSET), TAG(FIGCAPTION), TAG(FIGURE), TAG(FOOTER), TAG(HEADER),
3020
3020
  TAG(HGROUP), TAG(LISTING), TAG(MAIN), TAG(MENU), TAG(NAV), TAG(OL),
3021
- TAG(PRE), TAG(SECTION), TAG(SUMMARY), TAG(UL)
3021
+ TAG(PRE), TAG(SECTION), TAG(SUMMARY), TAG(UL), TAG(SEARCH)
3022
3022
  })
3023
3023
  ) {
3024
3024
  GumboTag tag = token->v.end_tag.tag;
@@ -3057,6 +3057,9 @@ static void handle_in_body(GumboParser* parser, GumboToken* token) {
3057
3057
  ignore_token(parser);
3058
3058
  return;
3059
3059
  }
3060
+ // Since we remove the form node without popping, we need to make sure
3061
+ // that we flush any text nodes at the end of the form.
3062
+ maybe_flush_text_node_buffer(parser);
3060
3063
  // This differs from implicitly_close_tags because we remove *only* the
3061
3064
  // <form> element; other nodes are left in scope.
3062
3065
  generate_implied_end_tags(parser, GUMBO_TAG_LAST, NULL);
@@ -3434,7 +3437,7 @@ static void handle_in_table(GumboParser* parser, GumboToken* token) {
3434
3437
  || token->type == GUMBO_TOKEN_WHITESPACE
3435
3438
  || token->type == GUMBO_TOKEN_NULL)
3436
3439
  && node_tag_in_set(get_current_node(parser), &(const TagSet) {
3437
- TAG(TABLE), TAG(TBODY), TAG(TFOOT), TAG(THEAD), TAG(TR)
3440
+ TAG(TABLE), TAG(TBODY), TAG(TEMPLATE), TAG(TFOOT), TAG(THEAD), TAG(TR)
3438
3441
  })
3439
3442
  ) {
3440
3443
  // The "pending table character tokens" list described in the spec is
@@ -4423,11 +4426,6 @@ static void handle_in_foreign_content(GumboParser* parser, GumboToken* token) {
4423
4426
  /* Parse error */
4424
4427
  parser_add_parse_error(parser, token);
4425
4428
 
4426
- /*
4427
- * Fragment case: If the parser was originally created for the HTML
4428
- * fragment parsing algorithm, then act as described in the "any other
4429
- * start tag" entry below.
4430
- */
4431
4429
  while (
4432
4430
  !(
4433
4431
  is_mathml_integration_point(get_current_node(parser))
@@ -4437,12 +4435,6 @@ static void handle_in_foreign_content(GumboParser* parser, GumboToken* token) {
4437
4435
  ) {
4438
4436
  pop_current_node(parser);
4439
4437
  }
4440
- // XXX: The spec currently says to handle this using the in body insertion
4441
- // mode rules. That seems wrong. See
4442
- // <https://github.com/whatwg/html/issues/6808>. Instead, use the current
4443
- // insertion mode which seems like it works.
4444
- //
4445
- // handle_in_body(parser, token);
4446
4438
  handle_html_content(parser, token);
4447
4439
  return;
4448
4440
  }
@@ -2,7 +2,7 @@
2
2
  #define GUMBO_REPLACEMENT_H_
3
3
 
4
4
  #include <stddef.h>
5
- #include "gumbo.h"
5
+ #include "nokogiri_gumbo.h"
6
6
 
7
7
  typedef struct {
8
8
  const char *const from;
@@ -4,7 +4,7 @@
4
4
  #include <stdbool.h>
5
5
  #include <stddef.h>
6
6
 
7
- #include "gumbo.h"
7
+ #include "nokogiri_gumbo.h"
8
8
 
9
9
  #ifdef __cplusplus
10
10
  extern "C" {
@@ -17,7 +17,7 @@
17
17
 
18
18
  #include <stddef.h>
19
19
  #include <string.h>
20
- #include "gumbo.h"
20
+ #include "nokogiri_gumbo.h"
21
21
  #include "ascii.h"
22
22
 
23
23
  bool gumbo_string_equals (
@@ -1,7 +1,7 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -m100 lib/svg_attrs.gperf */
2
+ /* Command-line: gperf -m100 src/svg_attrs.gperf */
3
3
  /* Computed positions: -k'1,10,$' */
4
- /* Filtered by: mk/gperf-filter.sed */
4
+ /* Filtered by: gperf-filter.sed */
5
5
 
6
6
  #include "replacement.h"
7
7
  #include "macros.h"
@@ -1,7 +1,7 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -m100 lib/svg_tags.gperf */
2
+ /* Command-line: gperf -m100 src/svg_tags.gperf */
3
3
  /* Computed positions: -k'3,7' */
4
- /* Filtered by: mk/gperf-filter.sed */
4
+ /* Filtered by: gperf-filter.sed */
5
5
 
6
6
  #include "replacement.h"
7
7
  #include "macros.h"
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- #include "gumbo.h"
17
+ #include "nokogiri_gumbo.h"
18
18
  #include "util.h"
19
19
  #include "tag_lookup.h"
20
20
 
@@ -172,6 +172,7 @@ static const char kGumboTagNames[GUMBO_TAG_LAST+1][15] = {
172
172
  [GUMBO_TAG_TT] = "tt",
173
173
  [GUMBO_TAG_RTC] = "rtc",
174
174
  [GUMBO_TAG_DIALOG] = "dialog",
175
+ [GUMBO_TAG_SEARCH] = "search",
175
176
 
176
177
  [GUMBO_TAG_UNKNOWN] = "",
177
178
  [GUMBO_TAG_LAST] = "",
@@ -1,14 +1,14 @@
1
1
  /* ANSI-C code produced by gperf version 3.1 */
2
- /* Command-line: gperf -m100 lib/tag_lookup.gperf */
2
+ /* Command-line: gperf -m100 src/tag_lookup.gperf */
3
3
  /* Computed positions: -k'1-2,$' */
4
- /* Filtered by: mk/gperf-filter.sed */
4
+ /* Filtered by: gperf-filter.sed */
5
5
 
6
6
  #include "tag_lookup.h"
7
7
  #include "macros.h"
8
8
  #include "ascii.h"
9
9
  #include <string.h>
10
10
 
11
- #define TOTAL_KEYWORDS 150
11
+ #define TOTAL_KEYWORDS 151
12
12
  #define MIN_WORD_LENGTH 1
13
13
  #define MAX_WORD_LENGTH 14
14
14
  #define MIN_HASH_VALUE 9
@@ -26,7 +26,7 @@ hash (register const char *str, register size_t len)
26
26
  272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
27
27
  272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
28
28
  272, 272, 272, 272, 272, 272, 272, 272, 272, 272,
29
- 272, 272, 272, 272, 272, 272, 272, 272, 272, 9,
29
+ 272, 272, 272, 272, 272, 272, 272, 272, 272, 11,
30
30
  7, 6, 4, 4, 3, 4, 3, 3, 272, 272,
31
31
  272, 272, 272, 272, 272, 70, 83, 152, 7, 16,
32
32
  61, 98, 5, 76, 102, 126, 12, 19, 54, 54,
@@ -69,7 +69,7 @@ gumbo_tag_lookup (register const char *str, register size_t len)
69
69
  static const unsigned char lengthtable[] =
70
70
  {
71
71
  0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2,
72
- 2, 2, 2, 6, 2, 6, 2, 4, 0, 7, 6, 3, 0, 3,
72
+ 2, 2, 2, 6, 2, 6, 6, 4, 2, 7, 6, 3, 0, 3,
73
73
  0, 6, 6, 8, 5, 0, 0, 4, 5, 5, 8, 0, 2, 4,
74
74
  5, 2, 0, 5, 4, 2, 0, 7, 0, 8, 5, 0, 0, 0,
75
75
  0, 0, 0, 5, 3, 4, 5, 1, 4, 0, 4, 1, 2, 8,
@@ -111,9 +111,9 @@ gumbo_tag_lookup (register const char *str, register size_t len)
111
111
  {"spacer", GUMBO_TAG_SPACER},
112
112
  {"h2", GUMBO_TAG_H2},
113
113
  {"header", GUMBO_TAG_HEADER},
114
- {"h1", GUMBO_TAG_H1},
114
+ {"search", GUMBO_TAG_SEARCH},
115
115
  {"head", GUMBO_TAG_HEAD},
116
- {(char*)0,GUMBO_TAG_UNKNOWN},
116
+ {"h1", GUMBO_TAG_H1},
117
117
  {"details", GUMBO_TAG_DETAILS},
118
118
  {"select", GUMBO_TAG_SELECT},
119
119
  {"dir", GUMBO_TAG_DIR},
@@ -167,3 +167,4 @@ spacer, GUMBO_TAG_SPACER
167
167
  tt, GUMBO_TAG_TT
168
168
  rtc, GUMBO_TAG_RTC
169
169
  dialog, GUMBO_TAG_DIALOG
170
+ search, GUMBO_TAG_SEARCH
@@ -1,7 +1,7 @@
1
1
  #ifndef GUMBO_TAG_LOOKUP_H_
2
2
  #define GUMBO_TAG_LOOKUP_H_
3
3
 
4
- #include "gumbo.h"
4
+ #include "nokogiri_gumbo.h"
5
5
 
6
6
  typedef struct {
7
7
  const char *key;
@@ -20,7 +20,7 @@
20
20
  #include <stdbool.h>
21
21
  #include <stddef.h>
22
22
 
23
- #include "gumbo.h"
23
+ #include "nokogiri_gumbo.h"
24
24
 
25
25
  #ifdef __cplusplus
26
26
  extern "C" {
@@ -50,7 +50,7 @@
50
50
  #include "attribute.h"
51
51
  #include "char_ref.h"
52
52
  #include "error.h"
53
- #include "gumbo.h"
53
+ #include "nokogiri_gumbo.h"
54
54
  #include "parser.h"
55
55
  #include "string_buffer.h"
56
56
  #include "token_type.h"
@@ -7,7 +7,7 @@
7
7
  #include <stdbool.h>
8
8
  #include <stddef.h>
9
9
 
10
- #include "gumbo.h"
10
+ #include "nokogiri_gumbo.h"
11
11
  #include "token_type.h"
12
12
  #include "tokenizer_states.h"
13
13
 
@@ -22,7 +22,7 @@
22
22
  #include <string.h>
23
23
 
24
24
  #include "error.h"
25
- #include "gumbo.h"
25
+ #include "nokogiri_gumbo.h"
26
26
  #include "parser.h"
27
27
  #include "ascii.h"
28
28
  #include "vector.h"
@@ -19,7 +19,7 @@
19
19
  #include <stdbool.h>
20
20
  #include <stddef.h>
21
21
 
22
- #include "gumbo.h"
22
+ #include "nokogiri_gumbo.h"
23
23
  #include "macros.h"
24
24
 
25
25
  #ifdef __cplusplus
@@ -19,7 +19,7 @@
19
19
  #include <stdlib.h>
20
20
  #include <string.h>
21
21
  #include "util.h"
22
- #include "gumbo.h"
22
+ #include "nokogiri_gumbo.h"
23
23
 
24
24
  void* gumbo_alloc(size_t size) {
25
25
  void* ptr = malloc(size);
@@ -63,6 +63,4 @@ void gumbo_debug(const char* format, ...) {
63
63
  va_end(args);
64
64
  fflush(stdout);
65
65
  }
66
- #else
67
- void gumbo_debug(const char* UNUSED_ARG(format), ...) {}
68
66
  #endif
@@ -21,7 +21,11 @@ void* gumbo_realloc(void* ptr, size_t size) RETURNS_NONNULL;
21
21
  void gumbo_free(void* ptr);
22
22
 
23
23
  // Debug wrapper for printf
24
+ #ifdef GUMBO_DEBUG
24
25
  void gumbo_debug(const char* format, ...) PRINTF(1);
26
+ #else
27
+ static inline void PRINTF(1) gumbo_debug(const char* UNUSED_ARG(format), ...) {};
28
+ #endif
25
29
 
26
30
  #ifdef __cplusplus
27
31
  }
@@ -1,7 +1,7 @@
1
1
  #ifndef GUMBO_VECTOR_H_
2
2
  #define GUMBO_VECTOR_H_
3
3
 
4
- #include "gumbo.h"
4
+ #include "nokogiri_gumbo.h"
5
5
 
6
6
  #ifdef __cplusplus
7
7
  extern "C" {
@@ -0,0 +1,67 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require "set"
5
+
6
+ module Nokogiri
7
+ #
8
+ # Some classes in Nokogiri are namespaced as a group, for example
9
+ # Document, DocumentFragment, and Builder.
10
+ #
11
+ # It's sometimes necessary to look up the related class, e.g.:
12
+ #
13
+ # XML::Builder → XML::Document
14
+ # HTML4::Builder → HTML4::Document
15
+ # HTML5::Document → HTML5::DocumentFragment
16
+ #
17
+ # This module is included into those key classes who need to do this.
18
+ #
19
+ module ClassResolver
20
+ # #related_class restricts matching namespaces to those matching this set.
21
+ VALID_NAMESPACES = Set.new(["HTML", "HTML4", "HTML5", "XML"])
22
+
23
+ # :call-seq:
24
+ # related_class(class_name) → Class
25
+ #
26
+ # Find a class constant within the
27
+ #
28
+ # Some examples:
29
+ #
30
+ # Nokogiri::XML::Document.new.related_class("DocumentFragment")
31
+ # # => Nokogiri::XML::DocumentFragment
32
+ # Nokogiri::HTML4::Document.new.related_class("DocumentFragment")
33
+ # # => Nokogiri::HTML4::DocumentFragment
34
+ #
35
+ # Note this will also work for subclasses that follow the same convention, e.g.:
36
+ #
37
+ # Loofah::HTML::Document.new.related_class("DocumentFragment")
38
+ # # => Loofah::HTML::DocumentFragment
39
+ #
40
+ # And even if it's a subclass, this will iterate through the superclasses:
41
+ #
42
+ # class ThisIsATopLevelClass < Nokogiri::HTML4::Builder ; end
43
+ # ThisIsATopLevelClass.new.related_class("Document")
44
+ # # => Nokogiri::HTML4::Document
45
+ #
46
+ def related_class(class_name)
47
+ klass = nil
48
+ inspecting = self.class
49
+
50
+ while inspecting
51
+ namespace_path = inspecting.name.split("::")[0..-2]
52
+ inspecting = inspecting.superclass
53
+
54
+ next unless VALID_NAMESPACES.include?(namespace_path.last)
55
+
56
+ related_class_name = (namespace_path << class_name).join("::")
57
+ klass = begin
58
+ Object.const_get(related_class_name)
59
+ rescue NameError
60
+ nil
61
+ end
62
+ break if klass
63
+ end
64
+ klass
65
+ end
66
+ end
67
+ end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nokogiri
3
4
  module CSS
4
- class Node
5
+ class Node # :nodoc:
5
6
  ALLOW_COMBINATOR_ON_SELF = [:DIRECT_ADJACENT_SELECTOR, :FOLLOWING_SELECTOR, :CHILD_SELECTOR]
6
7
 
7
8
  # Get the type of this node
@@ -10,25 +11,25 @@ module Nokogiri
10
11
  attr_accessor :value
11
12
 
12
13
  # Create a new Node with +type+ and +value+
13
- def initialize type, value
14
+ def initialize(type, value)
14
15
  @type = type
15
16
  @value = value
16
17
  end
17
18
 
18
19
  # Accept +visitor+
19
- def accept visitor
20
+ def accept(visitor)
20
21
  visitor.send(:"visit_#{type.to_s.downcase}", self)
21
22
  end
22
23
 
23
24
  ###
24
25
  # Convert this CSS node to xpath with +prefix+ using +visitor+
25
- def to_xpath prefix = '//', visitor = XPathVisitor.new
26
- prefix = '.' if ALLOW_COMBINATOR_ON_SELF.include?(type) && value.first.nil?
26
+ def to_xpath(prefix, visitor)
27
+ prefix = "." if ALLOW_COMBINATOR_ON_SELF.include?(type) && value.first.nil?
27
28
  prefix + visitor.accept(self)
28
29
  end
29
30
 
30
31
  # Find a node by type using +types+
31
- def find_by_type types
32
+ def find_by_type(types)
32
33
  matches = []
33
34
  matches << self if to_type == types
34
35
  @value.each do |v|
@@ -39,9 +40,9 @@ module Nokogiri
39
40
 
40
41
  # Convert to_type
41
42
  def to_type
42
- [@type] + @value.map { |n|
43
+ [@type] + @value.filter_map do |n|
43
44
  n.to_type if n.respond_to?(:to_type)
44
- }.compact
45
+ end
45
46
  end
46
47
 
47
48
  # Convert to array