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.
- checksums.yaml +4 -4
- data/Gemfile +41 -0
- data/LICENSE-DEPENDENCIES.md +830 -509
- data/LICENSE.md +1 -1
- data/README.md +23 -14
- data/bin/nokogiri +63 -50
- data/dependencies.yml +33 -66
- data/ext/nokogiri/extconf.rb +159 -63
- data/ext/nokogiri/gumbo.c +21 -11
- data/ext/nokogiri/html4_document.c +2 -2
- data/ext/nokogiri/html4_element_description.c +1 -1
- data/ext/nokogiri/html4_entity_lookup.c +2 -2
- data/ext/nokogiri/html4_sax_parser_context.c +3 -9
- data/ext/nokogiri/html4_sax_push_parser.c +1 -1
- data/ext/nokogiri/nokogiri.c +38 -51
- data/ext/nokogiri/nokogiri.h +26 -14
- data/ext/nokogiri/test_global_handlers.c +1 -1
- data/ext/nokogiri/xml_attr.c +3 -3
- data/ext/nokogiri/xml_attribute_decl.c +5 -5
- data/ext/nokogiri/xml_cdata.c +3 -3
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +53 -44
- data/ext/nokogiri/xml_document_fragment.c +1 -3
- data/ext/nokogiri/xml_dtd.c +11 -11
- data/ext/nokogiri/xml_element_content.c +3 -3
- data/ext/nokogiri/xml_element_decl.c +5 -5
- data/ext/nokogiri/xml_encoding_handler.c +28 -14
- data/ext/nokogiri/xml_entity_decl.c +6 -6
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +80 -14
- data/ext/nokogiri/xml_node.c +982 -396
- data/ext/nokogiri/xml_node_set.c +4 -6
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +133 -32
- data/ext/nokogiri/xml_relax_ng.c +1 -3
- data/ext/nokogiri/xml_sax_parser.c +23 -17
- data/ext/nokogiri/xml_sax_parser_context.c +11 -9
- data/ext/nokogiri/xml_sax_push_parser.c +1 -3
- data/ext/nokogiri/xml_schema.c +4 -6
- data/ext/nokogiri/xml_syntax_error.c +1 -1
- data/ext/nokogiri/xml_text.c +2 -2
- data/ext/nokogiri/xml_xpath_context.c +144 -114
- data/ext/nokogiri/xslt_stylesheet.c +122 -23
- data/gumbo-parser/Makefile +10 -0
- data/gumbo-parser/src/attribute.h +1 -1
- data/gumbo-parser/src/error.c +2 -2
- data/gumbo-parser/src/error.h +1 -1
- data/gumbo-parser/src/foreign_attrs.c +2 -2
- data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
- data/gumbo-parser/src/parser.c +8 -16
- data/gumbo-parser/src/replacement.h +1 -1
- data/gumbo-parser/src/string_buffer.h +1 -1
- data/gumbo-parser/src/string_piece.c +1 -1
- data/gumbo-parser/src/svg_attrs.c +2 -2
- data/gumbo-parser/src/svg_tags.c +2 -2
- data/gumbo-parser/src/tag.c +2 -1
- data/gumbo-parser/src/tag_lookup.c +7 -7
- data/gumbo-parser/src/tag_lookup.gperf +1 -0
- data/gumbo-parser/src/tag_lookup.h +1 -1
- data/gumbo-parser/src/token_buffer.h +1 -1
- data/gumbo-parser/src/tokenizer.c +1 -1
- data/gumbo-parser/src/tokenizer.h +1 -1
- data/gumbo-parser/src/utf8.c +1 -1
- data/gumbo-parser/src/utf8.h +1 -1
- data/gumbo-parser/src/util.c +1 -3
- data/gumbo-parser/src/util.h +4 -0
- data/gumbo-parser/src/vector.h +1 -1
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +9 -8
- data/lib/nokogiri/css/parser.rb +360 -341
- data/lib/nokogiri/css/parser.y +249 -244
- data/lib/nokogiri/css/parser_extras.rb +22 -20
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +4 -3
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +184 -85
- data/lib/nokogiri/css.rb +44 -6
- data/lib/nokogiri/decorators/slop.rb +8 -7
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +4 -3
- data/lib/nokogiri/gumbo.rb +1 -0
- data/lib/nokogiri/html.rb +16 -10
- data/lib/nokogiri/html4/builder.rb +1 -0
- data/lib/nokogiri/html4/document.rb +56 -164
- data/lib/nokogiri/html4/document_fragment.rb +11 -7
- data/lib/nokogiri/html4/element_description.rb +1 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +432 -532
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4/entity_lookup.rb +2 -1
- data/lib/nokogiri/html4/sax/parser.rb +5 -2
- data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
- data/lib/nokogiri/html4.rb +12 -5
- data/lib/nokogiri/html5/document.rb +126 -32
- data/lib/nokogiri/html5/document_fragment.rb +14 -4
- data/lib/nokogiri/html5/node.rb +12 -7
- data/lib/nokogiri/html5.rb +138 -222
- data/lib/nokogiri/jruby/dependencies.rb +2 -19
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version/constant.rb +2 -1
- data/lib/nokogiri/version/info.rb +32 -24
- data/lib/nokogiri/version.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +54 -3
- data/lib/nokogiri/xml/attribute_decl.rb +2 -1
- data/lib/nokogiri/xml/builder.rb +35 -33
- data/lib/nokogiri/xml/cdata.rb +2 -1
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +232 -143
- data/lib/nokogiri/xml/document_fragment.rb +88 -42
- data/lib/nokogiri/xml/dtd.rb +3 -2
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +2 -1
- data/lib/nokogiri/xml/entity_decl.rb +3 -2
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +44 -0
- data/lib/nokogiri/xml/node/save_options.rb +14 -8
- data/lib/nokogiri/xml/node.rb +708 -383
- data/lib/nokogiri/xml/node_set.rb +134 -59
- data/lib/nokogiri/xml/notation.rb +12 -0
- data/lib/nokogiri/xml/parse_options.rb +140 -56
- data/lib/nokogiri/xml/pp/character_data.rb +8 -6
- data/lib/nokogiri/xml/pp/node.rb +26 -26
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +3 -1
- data/lib/nokogiri/xml/reader.rb +20 -24
- data/lib/nokogiri/xml/relax_ng.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +20 -19
- data/lib/nokogiri/xml/sax/parser.rb +38 -36
- data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +7 -6
- data/lib/nokogiri/xml/searchable.rb +93 -62
- data/lib/nokogiri/xml/syntax_error.rb +5 -4
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
- data/lib/nokogiri/xml/xpath.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +2 -3
- data/lib/nokogiri/xml.rb +4 -3
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/nokogiri/xslt.rb +21 -13
- data/lib/nokogiri.rb +22 -27
- data/lib/xsd/xmlparser/nokogiri.rb +28 -25
- data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2445 -1919
- data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
- metadata +20 -171
- data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
- data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -2511
- data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +0 -31
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +0 -19
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
data/gumbo-parser/src/parser.c
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
#include "ascii.h"
|
25
25
|
#include "attribute.h"
|
26
26
|
#include "error.h"
|
27
|
-
#include "
|
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
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/* ANSI-C code produced by gperf version 3.1 */
|
2
|
-
/* Command-line: gperf -m100
|
2
|
+
/* Command-line: gperf -m100 src/svg_attrs.gperf */
|
3
3
|
/* Computed positions: -k'1,10,$' */
|
4
|
-
/* Filtered by:
|
4
|
+
/* Filtered by: gperf-filter.sed */
|
5
5
|
|
6
6
|
#include "replacement.h"
|
7
7
|
#include "macros.h"
|
data/gumbo-parser/src/svg_tags.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* ANSI-C code produced by gperf version 3.1 */
|
2
|
-
/* Command-line: gperf -m100
|
2
|
+
/* Command-line: gperf -m100 src/svg_tags.gperf */
|
3
3
|
/* Computed positions: -k'3,7' */
|
4
|
-
/* Filtered by:
|
4
|
+
/* Filtered by: gperf-filter.sed */
|
5
5
|
|
6
6
|
#include "replacement.h"
|
7
7
|
#include "macros.h"
|
data/gumbo-parser/src/tag.c
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
#include "
|
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
|
2
|
+
/* Command-line: gperf -m100 src/tag_lookup.gperf */
|
3
3
|
/* Computed positions: -k'1-2,$' */
|
4
|
-
/* Filtered by:
|
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
|
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,
|
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,
|
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
|
-
{"
|
114
|
+
{"search", GUMBO_TAG_SEARCH},
|
115
115
|
{"head", GUMBO_TAG_HEAD},
|
116
|
-
{
|
116
|
+
{"h1", GUMBO_TAG_H1},
|
117
117
|
{"details", GUMBO_TAG_DETAILS},
|
118
118
|
{"select", GUMBO_TAG_SELECT},
|
119
119
|
{"dir", GUMBO_TAG_DIR},
|
data/gumbo-parser/src/utf8.c
CHANGED
data/gumbo-parser/src/utf8.h
CHANGED
data/gumbo-parser/src/util.c
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
#include <stdlib.h>
|
20
20
|
#include <string.h>
|
21
21
|
#include "util.h"
|
22
|
-
#include "
|
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
|
data/gumbo-parser/src/util.h
CHANGED
@@ -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
|
}
|
data/gumbo-parser/src/vector.h
CHANGED
@@ -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
|
data/lib/nokogiri/css/node.rb
CHANGED
@@ -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
|
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
|
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
|
26
|
-
prefix =
|
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
|
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.
|
43
|
+
[@type] + @value.filter_map do |n|
|
43
44
|
n.to_type if n.respond_to?(:to_type)
|
44
|
-
|
45
|
+
end
|
45
46
|
end
|
46
47
|
|
47
48
|
# Convert to array
|