meteor 0.9.34 → 0.9.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +8 -0
- data/Gemfile.lock +1 -1
- data/lib/meteor/core/kernel.rb +97 -96
- data/lib/meteor/core/util/pattern_cache.rb +1 -1
- data/lib/meteor/element.rb +33 -29
- data/lib/meteor/elements.rb +1 -1
- data/lib/meteor/ml/html/parser_impl.rb +30 -35
- data/lib/meteor/ml/html4/parser_impl.rb +68 -65
- data/lib/meteor/ml/xhtml/parser_impl.rb +31 -34
- data/lib/meteor/ml/xhtml4/parser_impl.rb +50 -50
- data/lib/meteor/ml/xml/parser_impl.rb +5 -4
- data/lib/meteor.rb +2 -2
- metadata +1 -1
data/lib/meteor/element.rb
CHANGED
|
@@ -21,8 +21,8 @@ module Meteor
|
|
|
21
21
|
# @return [true,false] content normal flag (内容存在フラグ)
|
|
22
22
|
# @!attribute [rw] cx
|
|
23
23
|
# @return [true,false] comment extension tag flag (コメント拡張タグフラグ)
|
|
24
|
-
# @!attribute [rw]
|
|
25
|
-
# @return [true,false] child
|
|
24
|
+
# @!attribute [rw] childless
|
|
25
|
+
# @return [true,false] child childless flag (子要素なしフラグ)
|
|
26
26
|
# @!attribute [rw] parser
|
|
27
27
|
# @return [Meteor::Parser] parser(パーサ)
|
|
28
28
|
# @!attribute [rw] type_value
|
|
@@ -36,8 +36,8 @@ module Meteor
|
|
|
36
36
|
# @!attribute [rw] removed
|
|
37
37
|
# @return [true,false] deletion flag (削除フラグ)
|
|
38
38
|
#
|
|
39
|
-
class Element
|
|
40
|
-
attr_accessor :name, :attributes, :mixed_content, :raw_content, :pattern, :document_sync, :normal, :cx, :
|
|
39
|
+
class Element # rubocop:disable Metrics/ClassLength
|
|
40
|
+
attr_accessor :name, :attributes, :mixed_content, :raw_content, :pattern, :document_sync, :normal, :cx, :childless,
|
|
41
41
|
:parser, :type_value, :usable, :origin, :copy, :removed
|
|
42
42
|
|
|
43
43
|
alias tag name
|
|
@@ -46,8 +46,8 @@ module Meteor
|
|
|
46
46
|
alias empty normal
|
|
47
47
|
alias empty= normal=
|
|
48
48
|
|
|
49
|
-
alias mono
|
|
50
|
-
alias mono=
|
|
49
|
+
alias mono childless
|
|
50
|
+
alias mono= childless=
|
|
51
51
|
|
|
52
52
|
#
|
|
53
53
|
# initializer (イニシャライザ)
|
|
@@ -61,6 +61,7 @@ module Meteor
|
|
|
61
61
|
#
|
|
62
62
|
def initialize(*args)
|
|
63
63
|
case args.length
|
|
64
|
+
when Meteor::ZERO
|
|
64
65
|
when Meteor::ONE
|
|
65
66
|
if args[0].is_a?(String)
|
|
66
67
|
initialize_s(args[0])
|
|
@@ -71,7 +72,6 @@ module Meteor
|
|
|
71
72
|
end
|
|
72
73
|
when Meteor::TWO
|
|
73
74
|
initialize_two(args[0], args[1])
|
|
74
|
-
when Meteor::ZERO
|
|
75
75
|
else
|
|
76
76
|
raise ArgumentError
|
|
77
77
|
end
|
|
@@ -90,7 +90,7 @@ module Meteor
|
|
|
90
90
|
# @parser=nil
|
|
91
91
|
# @normal = false
|
|
92
92
|
# @cx = false
|
|
93
|
-
# @
|
|
93
|
+
# @childless = false
|
|
94
94
|
# @parent = false
|
|
95
95
|
@usable = true
|
|
96
96
|
end
|
|
@@ -121,7 +121,7 @@ module Meteor
|
|
|
121
121
|
@document = String.new(elm.document)
|
|
122
122
|
@normal = elm.normal
|
|
123
123
|
@cx = elm.cx
|
|
124
|
-
@
|
|
124
|
+
@childless = elm.childless
|
|
125
125
|
@origin = elm
|
|
126
126
|
# @usable = false
|
|
127
127
|
elm.copy = self
|
|
@@ -207,27 +207,31 @@ module Meteor
|
|
|
207
207
|
@document_sync = false
|
|
208
208
|
case @parser.doc_type
|
|
209
209
|
when Parser::HTML, Parser::HTML4
|
|
210
|
-
if @cx
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
210
|
+
@document = if @cx
|
|
211
|
+
# @pattern_cc = String.new('') << '<!-- @' << elm.name << ' ' << elm.attributes << '-->'
|
|
212
|
+
# << elm.mixed_content << '<!-- /@' << elm.name << ' -->'
|
|
213
|
+
"<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
|
|
214
|
+
elsif @normal
|
|
215
|
+
# @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>'
|
|
216
|
+
# << elm.mixed_content << '</' << elm.name << '>'
|
|
217
|
+
"<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
218
|
+
else
|
|
219
|
+
String.new('') << '<' << @name << @attributes << '>'
|
|
220
|
+
# @document = "<#{@name}#{@attributes}>"
|
|
221
|
+
end
|
|
220
222
|
when Parser::XHTML, Parser::XHTML4, Parser::XML
|
|
221
|
-
if @cx
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
@document = if @cx
|
|
224
|
+
# @pattern_cc = String.new('') << '<!-- @' << elm.name << ' ' << elm.attributes << '-->'
|
|
225
|
+
# << elm.mixed_content << '<!-- /@' << elm.name << ' -->'
|
|
226
|
+
"<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
|
|
227
|
+
elsif @normal
|
|
228
|
+
# @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>' << elm.mixed_content
|
|
229
|
+
# << '</' << elm.name << '>'
|
|
230
|
+
"<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
231
|
+
else
|
|
232
|
+
String.new('') << '<' << @name << @attributes << '/>'
|
|
233
|
+
# @document = "<#{@name}#{@attributes}/>"
|
|
234
|
+
end
|
|
231
235
|
end
|
|
232
236
|
else
|
|
233
237
|
@document
|
data/lib/meteor/elements.rb
CHANGED
|
@@ -45,8 +45,8 @@ module Meteor
|
|
|
45
45
|
# REQUIRED_M = [' required ',' required',' REQUIRED ',' REQUIRED']
|
|
46
46
|
REQUIRED_R = 'required\\s|required$|REQUIRED\\s|REQUIRED$'
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
RE_REQUIRED_M = Regexp.new(REQUIRED_M)
|
|
49
|
+
RE_REQUIRED_R = Regexp.new(REQUIRED_R)
|
|
50
50
|
|
|
51
51
|
#
|
|
52
52
|
# initializer (イニシャライザ)
|
|
@@ -56,9 +56,6 @@ module Meteor
|
|
|
56
56
|
#
|
|
57
57
|
def initialize(*args)
|
|
58
58
|
super()
|
|
59
|
-
@@match_tag = MATCH_TAG
|
|
60
|
-
@@match_tag_nne = MATCH_TAG_NNE
|
|
61
|
-
@@attr_bool = ATTR_BOOL
|
|
62
59
|
@doc_type = Parser::HTML
|
|
63
60
|
case args.length
|
|
64
61
|
when ZERO
|
|
@@ -100,8 +97,6 @@ module Meteor
|
|
|
100
97
|
|
|
101
98
|
element_three('meta', 'charset', '[a-zA-Z-]+', false)
|
|
102
99
|
|
|
103
|
-
element_three('meta', 'charset', '[a-zA-Z-]+', false) unless @elm_
|
|
104
|
-
|
|
105
100
|
@error_check = true
|
|
106
101
|
|
|
107
102
|
if @elm_
|
|
@@ -117,20 +112,20 @@ module Meteor
|
|
|
117
112
|
private :analyze_content_type
|
|
118
113
|
|
|
119
114
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
120
|
-
if
|
|
121
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
122
|
-
elsif
|
|
123
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
124
|
-
elsif
|
|
125
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
126
|
-
elsif
|
|
127
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
128
|
-
elsif
|
|
129
|
-
(
|
|
130
|
-
|
|
131
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
132
|
-
elsif
|
|
133
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
115
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
116
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_SELECTED_M, RE_SELECTED_R)
|
|
117
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
118
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_MULTIPLE_M, RE_MULTIPLE_R)
|
|
119
|
+
elsif match?('disabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
120
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_DISABLED_M, RE_DISABLED_R)
|
|
121
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
122
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_CHECKED_M, RE_CHECKED_R)
|
|
123
|
+
elsif match?('readonly', attr_name) &&
|
|
124
|
+
(match?('textarea',
|
|
125
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
126
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_READONLY_M, RE_READONLY_R)
|
|
127
|
+
elsif match?('required', attr_name) && match?(REQUIRE_ELEMENT, elm.name)
|
|
128
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_REQUIRED_M, RE_REQUIRED_R)
|
|
134
129
|
else
|
|
135
130
|
super(elm, attr_name, attr_value)
|
|
136
131
|
end
|
|
@@ -139,20 +134,20 @@ module Meteor
|
|
|
139
134
|
private :edit_attrs_
|
|
140
135
|
|
|
141
136
|
def get_attr_value_(elm, attr_name)
|
|
142
|
-
if
|
|
143
|
-
get_attr_value_r(elm,
|
|
144
|
-
elsif
|
|
145
|
-
get_attr_value_r(elm,
|
|
146
|
-
elsif
|
|
147
|
-
get_attr_value_r(elm,
|
|
148
|
-
elsif
|
|
149
|
-
get_attr_value_r(elm,
|
|
150
|
-
elsif
|
|
151
|
-
(
|
|
152
|
-
|
|
153
|
-
get_attr_value_r(elm,
|
|
154
|
-
elsif
|
|
155
|
-
get_attr_value_r(elm,
|
|
137
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
138
|
+
get_attr_value_r(elm, RE_SELECTED_M)
|
|
139
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
140
|
+
get_attr_value_r(elm, RE_MULTIPLE_M)
|
|
141
|
+
elsif match?('disabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
142
|
+
get_attr_value_r(elm, RE_DISABLED_M)
|
|
143
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
144
|
+
get_attr_value_r(elm, RE_CHECKED_M)
|
|
145
|
+
elsif match?('readonly', attr_name) &&
|
|
146
|
+
(match?('textarea',
|
|
147
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
148
|
+
get_attr_value_r(elm, RE_READONLY_M)
|
|
149
|
+
elsif match?('required', attr_name) && match?(REQUIRE_ELEMENT, elm.name)
|
|
150
|
+
get_attr_value_r(elm, RE_REQUIRED_M)
|
|
156
151
|
else
|
|
157
152
|
super(elm, attr_name)
|
|
158
153
|
end
|
|
@@ -7,30 +7,36 @@ module Meteor
|
|
|
7
7
|
#
|
|
8
8
|
# HTML4 parser (HTMLパーサ)
|
|
9
9
|
#
|
|
10
|
-
class ParserImpl < Meteor::Core::Kernel
|
|
10
|
+
class ParserImpl < Meteor::Core::Kernel # rubocop:disable Metrics/ClassLength
|
|
11
11
|
# KAIGYO_CODE = "\r?\n|\r"
|
|
12
12
|
# KAIGYO_CODE = "\r\n|\n|\r"
|
|
13
13
|
KAIGYO_CODE = ["\r\n", "\n", "\r"].freeze
|
|
14
14
|
BR = '<br>'
|
|
15
15
|
BR_RE = BR
|
|
16
16
|
|
|
17
|
-
#
|
|
17
|
+
# MATCH_TAG = "br|hr|img|input|meta|base"
|
|
18
|
+
|
|
18
19
|
# [Array] void elemets (空要素)
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
MATCH_TAG = %w[br hr img input meta base].freeze
|
|
21
|
+
|
|
22
|
+
# MATCH_TAG_TWO = "textarea|option|pre"
|
|
23
|
+
|
|
21
24
|
# [Array] elements where line breaks do not need to be converted to <br> (改行を<br>に変換する必要のない要素)
|
|
22
|
-
|
|
25
|
+
MATCH_TAG_TWO = %w[textarea option pre].freeze
|
|
23
26
|
|
|
24
27
|
# [Array] non-nestable elements (入れ子にできない要素)
|
|
25
|
-
|
|
28
|
+
MATCH_TAG_NNE = %w[texarea select option form fieldset].freeze
|
|
26
29
|
|
|
27
30
|
# [Array] boolean attributes (論理値で指定する属性)
|
|
28
|
-
|
|
31
|
+
ATTR_BOOL = %w[disabled readonly checked selected multiple].freeze
|
|
29
32
|
|
|
30
33
|
# DISABLE_ELEMENT = "input|textarea|select|optgroup"
|
|
34
|
+
|
|
31
35
|
# [Array] elements with the disabled attribute (disabled属性のある要素)
|
|
32
36
|
DISABLE_ELEMENT = %w[input textarea select optgroup].freeze
|
|
37
|
+
|
|
33
38
|
# READONLY_TYPE = "text|password"
|
|
39
|
+
|
|
34
40
|
# [Array] the type of an input element with a readonly attribute (readonly属性のあるinput要素のタイプ)
|
|
35
41
|
READONLY_TYPE = %w[text password].freeze
|
|
36
42
|
|
|
@@ -50,26 +56,25 @@ module Meteor
|
|
|
50
56
|
# MULTIPLE_M = [' multiple ',' multiple',' MULTIPLE ',' MULTIPLE']
|
|
51
57
|
MULTIPLE_R = 'multiple\\s|multiple$|MULTIPLE\\s|MULTIPLE$'
|
|
52
58
|
|
|
53
|
-
#
|
|
54
|
-
#
|
|
59
|
+
# RE_TRUE = Regexp.new("true")
|
|
60
|
+
# RE_FALSE = Regexp.new("false")
|
|
55
61
|
|
|
56
62
|
GET_ATTRS_MAP2 = '\\s(disabled|readonly|checked|selected|multiple)'
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
RE_SELECTED_M = Regexp.new(SELECTED_M)
|
|
65
|
+
RE_SELECTED_R = Regexp.new(SELECTED_R)
|
|
66
|
+
RE_CHECKED_M = Regexp.new(CHECKED_M)
|
|
67
|
+
RE_CHECKED_R = Regexp.new(CHECKED_R)
|
|
68
|
+
RE_DISABLED_M = Regexp.new(DISABLED_M)
|
|
69
|
+
RE_DISABLED_R = Regexp.new(DISABLED_R)
|
|
70
|
+
RE_READONLY_M = Regexp.new(READONLY_M)
|
|
71
|
+
RE_READONLY_R = Regexp.new(READONLY_R)
|
|
72
|
+
RE_MULTIPLE_M = Regexp.new(MULTIPLE_M)
|
|
73
|
+
RE_MULTIPLE_R = Regexp.new(MULTIPLE_R)
|
|
74
|
+
RE_GET_ATTRS_MAP2 = Regexp.new(GET_ATTRS_MAP2)
|
|
68
75
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# @@pattern_match_tag = Regexp.new(@@match_tag)
|
|
72
|
-
# @@pattern_match_tag2 = Regexp.new(@@match_tag_two)
|
|
76
|
+
# RE_MATCH_TAG = Regexp.new(MATCH_TAG)
|
|
77
|
+
# RE_MATCH_TAG_TWO = Regexp.new(MATCH_TAG_TWO)
|
|
73
78
|
|
|
74
79
|
#
|
|
75
80
|
# initializer (イニシャライザ)
|
|
@@ -149,8 +154,6 @@ module Meteor
|
|
|
149
154
|
|
|
150
155
|
element_three('meta', 'http-equiv', 'Content-Type')
|
|
151
156
|
|
|
152
|
-
element_three('meta', 'http-equiv', 'Content-Type') unless @elm_
|
|
153
|
-
|
|
154
157
|
@error_check = true
|
|
155
158
|
|
|
156
159
|
if @elm_
|
|
@@ -188,7 +191,7 @@ module Meteor
|
|
|
188
191
|
quote_name(name)
|
|
189
192
|
|
|
190
193
|
# case of void element (空要素の場合(<->内容あり要素の場合))
|
|
191
|
-
if
|
|
194
|
+
if match?(MATCH_TAG, name)
|
|
192
195
|
# void element search pattern (空要素検索用パターン)
|
|
193
196
|
@pattern_cc = String.new('') << '<' << @_name << '(|\\s[^<>]*)>'
|
|
194
197
|
# @pattern_cc = "<#{@_name}(|\\s[^<>]*)>"
|
|
@@ -256,7 +259,7 @@ module Meteor
|
|
|
256
259
|
end
|
|
257
260
|
|
|
258
261
|
# case of void element (空要素の場合(<->内容あり要素の場合))
|
|
259
|
-
if
|
|
262
|
+
if match?(MATCH_TAG, name)
|
|
260
263
|
# void element search pattern (空要素検索パターン)
|
|
261
264
|
# @pattern_cc = String.new('') << "<" << @_name << '(\\s[^<>]*' << @_attr_name << '="'
|
|
262
265
|
# @pattern_cc << @_attr_value << '"[^<>]*)>'
|
|
@@ -277,13 +280,13 @@ module Meteor
|
|
|
277
280
|
# @pattern_cc = String.new('') << "<" << @_name << '(\\s[^<>]*' << @_attr_name << '="'
|
|
278
281
|
# @pattern_cc << @_attr_value << '"[^<>]*)>(((?!(' << @_name
|
|
279
282
|
# @pattern_cc << '[^<>]*>)).)*)<\\/' << @_name << '>'
|
|
280
|
-
@pattern_cc = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"
|
|
283
|
+
@pattern_cc = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>" # rubocop:disable Layout/LineLength
|
|
281
284
|
|
|
282
285
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
283
286
|
# search of normal element (内容あり要素検索)
|
|
284
287
|
@res = @pattern.match(@root.document)
|
|
285
288
|
|
|
286
|
-
@res = element_normal_three_two if !@res && !
|
|
289
|
+
@res = element_normal_three_two if !@res && !match?(MATCH_TAG_NNE, name)
|
|
287
290
|
|
|
288
291
|
if @res
|
|
289
292
|
element_normal_three_one(name)
|
|
@@ -347,14 +350,14 @@ module Meteor
|
|
|
347
350
|
quote_element_five(name, attr_name1, attr_value1, attr_name2, attr_value2)
|
|
348
351
|
|
|
349
352
|
# case of void element (空要素の場合(<->内容あり要素の場合))
|
|
350
|
-
if
|
|
353
|
+
if match?(MATCH_TAG, name)
|
|
351
354
|
# void element search pattern (空要素検索パターン)
|
|
352
355
|
# @pattern_cc = String.new('') << "<" << @_name << '(\\s[^<>]*(?:' << @_attr_name1 << '="'
|
|
353
356
|
# @pattern_cc << @_attr_value1 << '"[^<>]*' << @_attr_name2 << '="'
|
|
354
357
|
# @pattern_cc << @_attr_value2 << '"|' << @_attr_name2 << '="'
|
|
355
358
|
# @pattern_cc << @_attr_value2 << '"[^<>]*' << @_attr_name1 << '="'
|
|
356
359
|
# @pattern_cc << @_attr_value1 << '")[^<>]*)>'
|
|
357
|
-
@pattern_cc = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>"
|
|
360
|
+
@pattern_cc = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>" # rubocop:disable Layout/LineLength
|
|
358
361
|
|
|
359
362
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
360
363
|
# void element search (空要素検索)
|
|
@@ -381,13 +384,13 @@ module Meteor
|
|
|
381
384
|
# @pattern_cc << @_attr_value2 << '"[^<>]*' << @_attr_name1 << '="'
|
|
382
385
|
# @pattern_cc << @_attr_value1 << '")[^<>]*)>(((?!(' << @_name
|
|
383
386
|
# @pattern_cc << '[^<>]*>)).)*)<\\/' << @_name << '>'
|
|
384
|
-
@pattern_cc = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"
|
|
387
|
+
@pattern_cc = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>" # rubocop:disable Layout/LineLength
|
|
385
388
|
|
|
386
389
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
387
390
|
# search of normal element (内容あり要素検索)
|
|
388
391
|
@res = @pattern.match(@root.document)
|
|
389
392
|
|
|
390
|
-
@res = element_normal_five_two if !@res && !
|
|
393
|
+
@res = element_normal_five_two if !@res && !match?(MATCH_TAG_NNE, name)
|
|
391
394
|
|
|
392
395
|
if @res
|
|
393
396
|
element_normal_five_one(name)
|
|
@@ -432,7 +435,7 @@ module Meteor
|
|
|
432
435
|
# @pattern_cc << '"|' << @_attr_name2 << '="' << @_attr_value2
|
|
433
436
|
# @pattern_cc << '"[^<>]*' << @_attr_name1 << '="' << @_attr_value1
|
|
434
437
|
# @pattern_cc << '")[^<>]*)>'
|
|
435
|
-
@pattern_cc = "<([^<>\"]*)\\s([^<>]*(#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>"
|
|
438
|
+
@pattern_cc = "<([^<>\"]*)\\s([^<>]*(#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>" # rubocop:disable Layout/LineLength
|
|
436
439
|
|
|
437
440
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
438
441
|
|
|
@@ -456,18 +459,18 @@ module Meteor
|
|
|
456
459
|
private :element_four
|
|
457
460
|
|
|
458
461
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
459
|
-
if
|
|
460
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
461
|
-
elsif
|
|
462
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
463
|
-
elsif
|
|
464
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
465
|
-
elsif
|
|
466
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
467
|
-
elsif
|
|
468
|
-
(
|
|
469
|
-
|
|
470
|
-
edit_attrs_five(elm, attr_name, attr_value,
|
|
462
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
463
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_SELECTED_M, RE_SELECTED_R)
|
|
464
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
465
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_MULTIPLE_M, RE_MULTIPLE_R)
|
|
466
|
+
elsif match?('disabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
467
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_DISABLED_M, RE_DISABLED_R)
|
|
468
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
469
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_CHECKED_M, RE_CHECKED_R)
|
|
470
|
+
elsif match?('readonly', attr_name) &&
|
|
471
|
+
(match?('textarea',
|
|
472
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
473
|
+
edit_attrs_five(elm, attr_name, attr_value, RE_READONLY_M, RE_READONLY_R)
|
|
471
474
|
else
|
|
472
475
|
super(elm, attr_name, attr_value)
|
|
473
476
|
end
|
|
@@ -476,7 +479,7 @@ module Meteor
|
|
|
476
479
|
private :edit_attrs_
|
|
477
480
|
|
|
478
481
|
def edit_attrs_five(elm, attr_name, attr_value, match_p, replace)
|
|
479
|
-
if true.equal?(attr_value) ||
|
|
482
|
+
if true.equal?(attr_value) || match?('true', attr_value)
|
|
480
483
|
@res = match_p.match(elm.attributes)
|
|
481
484
|
|
|
482
485
|
unless @res
|
|
@@ -489,7 +492,7 @@ module Meteor
|
|
|
489
492
|
elm.attributes << ' ' << attr_name
|
|
490
493
|
# else
|
|
491
494
|
end
|
|
492
|
-
elsif false.equal?(attr_value) ||
|
|
495
|
+
elsif false.equal?(attr_value) || match?('false', attr_value)
|
|
493
496
|
elm.attributes.sub!(replace, '')
|
|
494
497
|
end
|
|
495
498
|
end
|
|
@@ -503,18 +506,18 @@ module Meteor
|
|
|
503
506
|
private :edit_document_one
|
|
504
507
|
|
|
505
508
|
def get_attr_value_(elm, attr_name)
|
|
506
|
-
if
|
|
507
|
-
get_attr_value_r(elm,
|
|
508
|
-
elsif
|
|
509
|
-
get_attr_value_r(elm,
|
|
510
|
-
elsif
|
|
511
|
-
get_attr_value_r(elm,
|
|
512
|
-
elsif
|
|
513
|
-
get_attr_value_r(elm,
|
|
514
|
-
elsif
|
|
515
|
-
(
|
|
516
|
-
|
|
517
|
-
get_attr_value_r(elm,
|
|
509
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
510
|
+
get_attr_value_r(elm, RE_SELECTED_M)
|
|
511
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
512
|
+
get_attr_value_r(elm, RE_MULTIPLE_M)
|
|
513
|
+
elsif match?('disabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
514
|
+
get_attr_value_r(elm, RE_DISABLED_M)
|
|
515
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
516
|
+
get_attr_value_r(elm, RE_CHECKED_M)
|
|
517
|
+
elsif match?('readonly', attr_name) &&
|
|
518
|
+
(match?('textarea',
|
|
519
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
520
|
+
get_attr_value_r(elm, RE_READONLY_M)
|
|
518
521
|
else
|
|
519
522
|
super(elm, attr_name)
|
|
520
523
|
end
|
|
@@ -553,11 +556,11 @@ module Meteor
|
|
|
553
556
|
def get_attrs(elm)
|
|
554
557
|
attrs = {}
|
|
555
558
|
|
|
556
|
-
elm.attributes.scan(
|
|
559
|
+
elm.attributes.scan(RE_GET_ATTRS_MAP) do |a, b|
|
|
557
560
|
attrs.store(a, unescape(b))
|
|
558
561
|
end
|
|
559
562
|
|
|
560
|
-
elm.attributes.scan(
|
|
563
|
+
elm.attributes.scan(RE_GET_ATTRS_MAP2) do |a|
|
|
561
564
|
attrs.store(a[0], 'true')
|
|
562
565
|
end
|
|
563
566
|
|
|
@@ -574,11 +577,11 @@ module Meteor
|
|
|
574
577
|
def get_attr_map(elm)
|
|
575
578
|
attrs = Meteor::AttributeMap.new
|
|
576
579
|
|
|
577
|
-
elm.attributes.scan(
|
|
580
|
+
elm.attributes.scan(RE_GET_ATTRS_MAP) do |a, b|
|
|
578
581
|
attrs.store(a, unescape(b))
|
|
579
582
|
end
|
|
580
583
|
|
|
581
|
-
elm.attributes.scan(
|
|
584
|
+
elm.attributes.scan(RE_GET_ATTRS_MAP2) do |a|
|
|
582
585
|
attrs.store(a[0], 'true')
|
|
583
586
|
end
|
|
584
587
|
|
|
@@ -590,7 +593,7 @@ module Meteor
|
|
|
590
593
|
private :get_attr_map
|
|
591
594
|
|
|
592
595
|
def remove_attrs_(elm, attr_name)
|
|
593
|
-
@pattern = if !
|
|
596
|
+
@pattern = if !match?(ATTR_BOOL, attr_name)
|
|
594
597
|
# attribute search pattern (属性検索用パターン)
|
|
595
598
|
Meteor::Core::Util::PatternCache.get(String.new('') << attr_name << '="[^"]*"\\s?')
|
|
596
599
|
# @pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"[^\"]*\"\\s?")
|
|
@@ -22,9 +22,9 @@ module Meteor
|
|
|
22
22
|
REQUIRED_R = 'required="[^"]*"'
|
|
23
23
|
REQUIRED_U = 'required="required"'
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
RE_REQUIRED_M = Regexp.new(REQUIRED_M)
|
|
26
|
+
RE_REQUIRED_M1 = Regexp.new(REQUIRED_M1)
|
|
27
|
+
RE_REQUIRED_R = Regexp.new(REQUIRED_R)
|
|
28
28
|
|
|
29
29
|
#
|
|
30
30
|
# initializer (イニシャライザ)
|
|
@@ -34,7 +34,6 @@ module Meteor
|
|
|
34
34
|
#
|
|
35
35
|
def initialize(*args)
|
|
36
36
|
super()
|
|
37
|
-
@@attr_bool = ATTR_BOOL
|
|
38
37
|
@doc_type = Parser::XHTML
|
|
39
38
|
case args.length
|
|
40
39
|
when ZERO
|
|
@@ -76,8 +75,6 @@ module Meteor
|
|
|
76
75
|
|
|
77
76
|
element_three('meta', 'charset', '[a-zA-Z-]+', false)
|
|
78
77
|
|
|
79
|
-
element_three('meta', 'charset', '[a-zA-Z-]+', false) unless @elm_
|
|
80
|
-
|
|
81
78
|
@error_check = true
|
|
82
79
|
|
|
83
80
|
if @elm_
|
|
@@ -93,20 +90,20 @@ module Meteor
|
|
|
93
90
|
private :analyze_content_type
|
|
94
91
|
|
|
95
92
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
96
|
-
if
|
|
97
|
-
edit_attrs_five(elm, attr_value,
|
|
98
|
-
elsif
|
|
99
|
-
edit_attrs_five(elm, attr_value,
|
|
100
|
-
elsif
|
|
101
|
-
edit_attrs_five(elm, attr_value,
|
|
102
|
-
elsif
|
|
103
|
-
edit_attrs_five(elm, attr_value,
|
|
104
|
-
elsif
|
|
105
|
-
(
|
|
106
|
-
|
|
107
|
-
edit_attrs_five(elm, attr_value,
|
|
108
|
-
elsif
|
|
109
|
-
edit_attrs_five(elm, attr_value,
|
|
93
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
94
|
+
edit_attrs_five(elm, attr_value, RE_SELECTED_M, RE_SELECTED_R, SELECTED_U)
|
|
95
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
96
|
+
edit_attrs_five(elm, attr_value, RE_MULTIPLE_M, RE_MULTIPLE_R, MULTIPLE_U)
|
|
97
|
+
elsif match?('disabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
98
|
+
edit_attrs_five(elm, attr_value, RE_DISABLED_M, RE_DISABLED_R, DISABLED_U)
|
|
99
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
100
|
+
edit_attrs_five(elm, attr_value, RE_CHECKED_M, RE_CHECKED_R, CHECKED_U)
|
|
101
|
+
elsif match?('readonly', attr_name) &&
|
|
102
|
+
(match?('textarea',
|
|
103
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
104
|
+
edit_attrs_five(elm, attr_value, RE_READONLY_M, RE_READONLY_R, READONLY_U)
|
|
105
|
+
elsif match?('required', attr_name) && match?(REQUIRE_ELEMENT, elm.name)
|
|
106
|
+
edit_attrs_five(elm, attr_value, RE_REQUIRED_M, RE_REQUIRED_R, REQUIRED_U)
|
|
110
107
|
else
|
|
111
108
|
super(elm, attr_name, attr_value)
|
|
112
109
|
end
|
|
@@ -115,20 +112,20 @@ module Meteor
|
|
|
115
112
|
private :edit_attrs_
|
|
116
113
|
|
|
117
114
|
def get_attr_value_(elm, attr_name)
|
|
118
|
-
if
|
|
119
|
-
get_attr_value_r(elm, attr_name,
|
|
120
|
-
elsif
|
|
121
|
-
get_attr_value_r(elm, attr_name,
|
|
122
|
-
elsif
|
|
123
|
-
get_attr_value_r(elm, attr_name,
|
|
124
|
-
elsif
|
|
125
|
-
get_attr_value_r(elm, attr_name,
|
|
126
|
-
elsif
|
|
127
|
-
(
|
|
128
|
-
|
|
129
|
-
get_attr_value_r(elm, attr_name,
|
|
130
|
-
elsif
|
|
131
|
-
get_attr_value_r(elm, attr_name,
|
|
115
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
116
|
+
get_attr_value_r(elm, attr_name, RE_SELECTED_M1)
|
|
117
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
118
|
+
get_attr_value_r(elm, attr_name, RE_MULTIPLE_M1)
|
|
119
|
+
elsif match?('disabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
120
|
+
get_attr_value_r(elm, attr_name, RE_DISABLED_M1)
|
|
121
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
122
|
+
get_attr_value_r(elm, attr_name, RE_CHECKED_M1)
|
|
123
|
+
elsif match?('readonly', attr_name) &&
|
|
124
|
+
(match?('textarea',
|
|
125
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
126
|
+
get_attr_value_r(elm, attr_name, RE_READONLY_M1)
|
|
127
|
+
elsif match?('required', attr_name) && match?(REQUIRE_ELEMENT, elm.name)
|
|
128
|
+
get_attr_value_r(elm, attr_name, RE_REQUIRED_M1)
|
|
132
129
|
else
|
|
133
130
|
super(elm, attr_name)
|
|
134
131
|
end
|