code-ruby 3.0.12 → 3.0.13
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/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/format.rb +13 -2
- data/lib/code/object/string.rb +13 -0
- data/spec/code/format_spec.rb +3 -1
- data/spec/code/object/string_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6baa3c7c3ef6b602529e2af4a36200029291ed89c115f1c1f3d750a8e815cc03
|
|
4
|
+
data.tar.gz: aa9c876fb0aff915f895ec3d209d25ac06270e3809eadba8f5e71b37b9cb29db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 444adc5d9b9a5223b82a921a888558a2f23dc40344a12b383137581b910ba4e33ea13873a2e5ce6698dc130ae77775cf9aa5b3e0e23f70947418301831df96b9
|
|
7
|
+
data.tar.gz: bcf7ecebc28788a2cf7464e3a7b67f32b2bfb86ec3d6365ca58674914d852181d27f3a051b596665807acd67291c2026d227b98d33603260e3122417e04d6a76
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.0.
|
|
1
|
+
3.0.13
|
data/lib/code/format.rb
CHANGED
|
@@ -434,7 +434,7 @@ class Code
|
|
|
434
434
|
|
|
435
435
|
Array(operation[:others]).each do |other|
|
|
436
436
|
right = format_nested_statement(other[:statement], indent: indent)
|
|
437
|
-
operator = other[:operator]
|
|
437
|
+
operator = format_operator(other[:operator])
|
|
438
438
|
|
|
439
439
|
expression =
|
|
440
440
|
if compact_operator?(operator)
|
|
@@ -532,7 +532,7 @@ class Code
|
|
|
532
532
|
end
|
|
533
533
|
|
|
534
534
|
def format_right_operation(operation, indent:)
|
|
535
|
-
operator = operation[:operator]
|
|
535
|
+
operator = format_operator(operation[:operator])
|
|
536
536
|
left =
|
|
537
537
|
if %w[if unless].include?(operator)
|
|
538
538
|
format_modifier_left(operation[:left], indent: indent)
|
|
@@ -595,6 +595,17 @@ class Code
|
|
|
595
595
|
%w[. :: &. .. ...].include?(operator)
|
|
596
596
|
end
|
|
597
597
|
|
|
598
|
+
def format_operator(operator)
|
|
599
|
+
case operator.to_s
|
|
600
|
+
when "||"
|
|
601
|
+
"or"
|
|
602
|
+
when "&&"
|
|
603
|
+
"and"
|
|
604
|
+
else
|
|
605
|
+
operator.to_s
|
|
606
|
+
end
|
|
607
|
+
end
|
|
608
|
+
|
|
598
609
|
def format_ternary(ternary, indent:)
|
|
599
610
|
left = format_nested_statement(ternary[:left], indent: indent)
|
|
600
611
|
middle = format_nested_statement(ternary[:middle], indent: indent)
|
data/lib/code/object/string.rb
CHANGED
|
@@ -157,6 +157,10 @@ class Code
|
|
|
157
157
|
|
|
158
158
|
def code_strip
|
|
159
159
|
String.new(raw.strip)
|
|
160
|
+
rescue ArgumentError, Encoding::CompatibilityError => e
|
|
161
|
+
raise unless e.message.include?("invalid byte sequence")
|
|
162
|
+
|
|
163
|
+
String.new(sanitized_utf8_raw.strip)
|
|
160
164
|
end
|
|
161
165
|
|
|
162
166
|
def code_split(value)
|
|
@@ -172,6 +176,15 @@ class Code
|
|
|
172
176
|
def present?
|
|
173
177
|
raw.present?
|
|
174
178
|
end
|
|
179
|
+
|
|
180
|
+
private
|
|
181
|
+
|
|
182
|
+
def sanitized_utf8_raw
|
|
183
|
+
raw
|
|
184
|
+
.dup
|
|
185
|
+
.force_encoding(::Encoding::UTF_8)
|
|
186
|
+
.encode(::Encoding::UTF_8, invalid: :replace, undef: :replace)
|
|
187
|
+
end
|
|
175
188
|
end
|
|
176
189
|
end
|
|
177
190
|
end
|
data/spec/code/format_spec.rb
CHANGED
|
@@ -13,6 +13,8 @@ RSpec.describe Code::Format do
|
|
|
13
13
|
%w[100000 100_000],
|
|
14
14
|
%w[1000000 1_000_000],
|
|
15
15
|
%w[1.0000000001 1.000_000_000_1],
|
|
16
|
+
["true || false", "true or false"],
|
|
17
|
+
["true && false", "true and false"],
|
|
16
18
|
["{a:1}", "{ a: 1 }"],
|
|
17
19
|
["[1,2,3]", "[1, 2, 3]"],
|
|
18
20
|
["[1, 2, 3].select { |n| n.even? }", "[1, 2, 3].select { |n| n.even? }"],
|
|
@@ -54,7 +56,7 @@ RSpec.describe Code::Format do
|
|
|
54
56
|
],
|
|
55
57
|
[
|
|
56
58
|
"sections << Html.join([Html.p { Html.b { \"{index + 1}. {title}\" } }, Html.p { query } if query.presence, Html.p { Html.a(href: link || inline_url) { :source } } if (link || inline_url), Html.p { Html.a(href: inline_url) { Html.img(src: inline_url, alt: title) } }, Html.p { Html.a(href: attachment_url) { \"télécharger\" } }].compact)",
|
|
57
|
-
"sections << Html.join(\n [\n Html.p { Html.b { \"{index + 1}. {title}\" } },\n Html.p { query } if query.presence,\n Html.p {\n Html.a(href: link
|
|
59
|
+
"sections << Html.join(\n [\n Html.p { Html.b { \"{index + 1}. {title}\" } },\n Html.p { query } if query.presence,\n Html.p {\n Html.a(href: link or inline_url) { :source }\n } if (link or inline_url),\n Html.p {\n Html.a(href: inline_url) { Html.img(src: inline_url, alt: title) }\n },\n Html.p {\n Html.a(href: attachment_url) { \"télécharger\" }\n }\n ].compact\n)"
|
|
58
60
|
],
|
|
59
61
|
[
|
|
60
62
|
"safe = post.present? and !post[:over_18] and post[:post_hint] == :image and post[:url].to_string.strip.presence and (post[:url].to_string.strip.ends_with?(\".jpg\") or post[:url].to_string.strip.ends_with?(\".jpeg\") or post[:url].to_string.strip.ends_with?(\".png\") or post[:url].to_string.strip.include?(\"i.redd.it\"))",
|
|
@@ -15,4 +15,12 @@ RSpec.describe Code::Object::String do
|
|
|
15
15
|
expect(Code.evaluate(input).to_s).to eq(expected)
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
describe "#code_strip" do
|
|
20
|
+
it "replaces invalid utf-8 bytes instead of raising" do
|
|
21
|
+
string = described_class.new("\xC3 ".b.force_encoding(Encoding::UTF_8))
|
|
22
|
+
|
|
23
|
+
expect(string.code_strip.to_s).to eq("\uFFFD")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
18
26
|
end
|