Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 7306b15

Browse files
committed
final touches
1 parent c85a1d6 commit 7306b15

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
99
* Add compatibility with Rails 7.1
1010
* Add compatibility with HAML 6
1111
* NOTE: Don't use HAML 6.0.0. AngularXSS relies on a patch [introduced in 6.0.1](https://github.com/haml/haml/blob/main/CHANGELOG.md#601). Anything newer should be fine - the gem is currently tested against HAML 6.3
12+
* Refactor our patches to use `Module#prepend` instead of `Module#module_eval`
13+
* Refactor gem version comparisons to use `Gem::Version` instances
14+
* Refactor specs to use the `expect` syntax
15+
* Add missing unit tests for patched methods
16+
* Improve test coverage for more interpolation scenarios in ERB and HAML
1217

1318
### Breaking changes
1419

spec/angular_xss/erb_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe ERB::Util do
66
describe '#html_escape' do
7-
it 'escapes angular brackets' do
7+
it 'escapes angular braces' do
88
expect(described_class.html_escape("{{unsafe}}")).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
99
end
1010

@@ -14,7 +14,7 @@
1414
end
1515

1616
describe '#h' do
17-
it 'escapes angular brackets' do
17+
it 'escapes angular braces' do
1818
expect(described_class.h("{{unsafe}}")).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
1919
end
2020

@@ -26,7 +26,7 @@
2626
# Rails < 4 does not implement unwrapped_html_escape and html_escape_once
2727
if described_class.method_defined? :unwrapped_html_escape
2828
describe '#unwrapped_html_escape' do
29-
it 'escapes angular brackets' do
29+
it 'escapes angular braces' do
3030
expect(described_class.unwrapped_html_escape("{{unsafe}}")).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
3131
end
3232

@@ -38,7 +38,7 @@
3838

3939
if described_class.method_defined? :html_escape_once
4040
describe '#html_escape_once' do
41-
it 'escapes angular brackets' do
41+
it 'escapes angular braces' do
4242
expect(described_class.html_escape_once("{{unsafe}}")).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
4343
end
4444

spec/angular_xss/escaper_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe AngularXss::Escaper do
22
describe '.escape' do
3-
it 'replaces double brackets with a closed variant' do
3+
it 'replaces double braces with a closed variant' do
44
expect(described_class.escape('{{')).to eq('{{ $root.DOUBLE_LEFT_CURLY_BRACE }}')
55
end
66

@@ -10,7 +10,7 @@
1010
end
1111

1212
describe '.escape_if_unsafe' do
13-
it 'replaces double brackets with a closed variant' do
13+
it 'replaces double braces with a closed variant' do
1414
expect(described_class.escape_if_unsafe('{{')).to eq('{{ $root.DOUBLE_LEFT_CURLY_BRACE }}')
1515
end
1616

spec/angular_xss/output_buffer_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe ActionView::OutputBuffer do
22
describe '#<<' do
3-
it 'escapes angular brackets' do
3+
it 'escapes angular braces' do
44
expect((subject << "{{unsafe}}").to_s).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
55
end
66

@@ -14,7 +14,7 @@
1414
end
1515

1616
describe '#concat' do
17-
it 'escapes angular brackets' do
17+
it 'escapes angular braces' do
1818
expect((subject.concat "{{unsafe}}").to_s).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
1919
end
2020

@@ -28,7 +28,7 @@
2828
end
2929

3030
describe '#append=' do
31-
it 'escapes angular brackets' do
31+
it 'escapes angular braces' do
3232
subject.append = "{{unsafe}}"
3333
expect(subject.to_s).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
3434
end

spec/angular_xss/safe_buffer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe ActiveSupport::SafeBuffer do
22

33
describe '#<<' do
4-
it 'escapes angular brackets' do
4+
it 'escapes angular braces' do
55
subject << "{{unsafe}}"
66
expect(subject.to_s).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
77
end
@@ -12,7 +12,7 @@
1212
end
1313

1414
describe '#+' do
15-
it 'escapes angular brackets' do
15+
it 'escapes angular braces' do
1616
combined_string = subject + "{{unsafe}}"
1717
expect(combined_string.to_s).to eq("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
1818
end

spec/support/engine_preventing_angular_xss.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
end
1717

1818
it 'recognizes the many ways to express an opening curly brace in HTML' do
19-
19+
# Only unsafe strings are escaped
2020
expect(html).to include("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}unsafe}}")
2121
expect(html).not_to include("{{ $root.DOUBLE_LEFT_CURLY_BRACE }}safe}}")
22+
23+
# Only safe strings with braces are left untouched
2224
expect(html).to include("{{safe}}")
2325
expect(html).not_to include("{{unsafe}}")
2426

0 commit comments

Comments
 (0)