Commit Graph

47 Commits

Author SHA1 Message Date
Akira Matsuda
4cb20843eb Mark scrub as an unsafe method on SafeBuffer 2020-12-01 17:40:17 +09:00
Akira Matsuda
2b2ed7bc0e All these tested String methods are public 2020-10-02 15:52:09 +09:00
Michael Grosser
203998c916
allow running each test with pure ruby path/to/test.rb
also:
 - makes test dependencies obvious
 - makes tests runnable from within subfolders
2019-12-18 08:49:19 -06:00
Shugo Maeda
dc87302cdf
Enumerator should be supported by ActiveSupport::SafeBuffer
Back references cannot be set because C level Proc doesn't support Binding.
This commit fixes #37422.
2019-10-17 22:51:09 +09:00
r7kamura
9dd254c2a2 Preserve html_safe? status on ActiveSupport::SafeBuffer#* 2019-04-19 06:32:55 +09:00
Matthew Draper
78ace9cd08
Merge pull request #34405 from shugo/safe_buffer_backref_fix
sub, sub!, gsub, and gsub! should set back references
2019-03-28 23:32:52 +10:30
Richard Monette
af20522954 support slice assignment on SafeBuffer 2019-03-13 19:22:04 -04:00
alkesh26
38472af70e ActiveSupport typo fixes. 2019-02-01 22:17:10 +05:30
Shugo Maeda
3891c725ad
sub, sub!, gsub, and gsub! should set back references 2018-11-08 21:02:45 +09:00
Janosch Müller
47f2686148 Handle more unsafe String methods (#33990)
* Handle more unsafe String methods

* Fix codeclimate issue

* Revert stylistic change

[Janosch Müller + Rafael Mendonça França]
2018-09-27 20:50:21 -04:00
Yumin Wong
0a1567793b Use assert_predicate instead
Co-authored-by: no-itsbackpack <no-itsbackpack@github.com>
2018-09-06 12:48:50 -05:00
Yumin Wong
3f5bd11ed6 SafeBuffer should maintain safety upon getting a slice via a range if original buffer was safe.
Co-Authored-By: no-itsbackpack <no-itsbackpack@github.com>
2018-08-31 11:46:09 -05:00
Ryuta Kamizono
1dc17e7b2e Fix CustomCops/AssertNot to allow it to have failure message
Follow up of #32605.
2018-05-13 11:32:47 +09:00
Daniel Colson
94333a4c31 Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
Koichi ITO
ac717d65a3 [Active Support] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
Kir Shatrov
72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Akira Matsuda
019cc5960d "Use assert_nil if expecting nil from ...:in `...'. This will fail in minitest 6." 2016-12-25 13:15:56 +09:00
Akira Matsuda
4ba9e61d99 Expectation first 2016-12-25 13:15:56 +09:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Xavier Noria
a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Godfrey Chan
debe7aedda Properly dump primitive-like AS::SafeBuffer strings as YAML
`coder.represent_scalar` means something along the lines of "Here is a quoted
string, you can just add it to the output", which is not the case here. It only
works for simple strings that can appear unquoted in YAML, but causes problems
for e.g. primitive-like strings ("1", "true").

`coder.represent_object` on the other hand, means that "This is the Ruby-object
representation for this thing suitable for use in YAML dumping", which is what
we want here.

Before:

   YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml  # => "Hello"
   YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml   # => true
   YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml  # => false
   YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml      # => 1
   YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml    # => 1.1

 After:

   YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml  # => "Hello"
   YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml   # => "true"
   YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml  # => "false"
   YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml      # => "1"
   YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml    # => "1.1"

If we ever want Ruby to behave more like PHP or JavaScript though, this is an
excellent trick to use ;)
2015-02-11 17:08:13 -08:00
Rafael Mendonça França
54ec0cbf82 Just check if the buffer exists before changing it 2014-12-29 12:56:01 -03:00
Vipul A M
983674667a When trying to access a character on a string buffer object via :[], if the object being accessed currently returns html_safe? as true,
we used to set  `@html_safe` variable as true on new object created. When doing something like

x = 'Hello'.html_safe
x[/a/, 1]

would throw an error on ruby 2.2, since when nothign gets matched nil is returned by the code and it tries to set   `@html_safe` value to true,
which would error since starting 2.2 nil is frozen.

This change adds a safety net to avoid setting `@html_safe = true` on frozen objects.

Fixes #18235
2014-12-29 18:31:34 +05:30
Julien Letessier
a764938ad0 Fixes interpolation on SafeBuffer
Interpolation was untested and did not work with hash arguments.

Adds
- support for interpolation with hash argument
- tests for the above
- tests for safe/unsafe interpolation
2013-12-14 10:10:47 +00:00
José Valim
8ccaa34103 Ensure [] respects the status of the buffer. 2012-02-29 16:09:02 -08:00
Akira Matsuda
71d8c77e5a delete vulnerable AS::SafeBuffer#[] 2012-02-20 16:02:45 -08:00
Akira Matsuda
71b95bd954 add AS::SafeBuffer#clone_empty 2012-02-20 16:02:44 -08:00
Aaron Patterson
ef7fc6ebb3 global variables may not be set depending on the match. fixes #4703 2012-01-26 09:24:14 -08:00
Rafael Mendonça França
7d26fad384 No need to require psych since require yaml does that. 2012-01-04 14:29:13 -03:00
Rafael Mendonça França
761b049b2e No need to use rescue block to require psych 2012-01-04 13:30:57 -03:00
Rafael Mendonça França
38b9fbf1d9 Whitespaces ✂️ 2012-01-04 12:39:28 -03:00
Rafael Mendonça França
73a0f9df47 Add test to make sure that add two safe buffers always return a safe buffer 2012-01-04 12:37:20 -03:00
José Valim
6b010c2690 Revert removing gsub and sub from safe buffer. 2011-09-08 20:54:30 +02:00
Xavier Noria
827fcf453e this should have gone with the previous commit 2011-09-08 05:02:47 -07:00
Damien Mathieu
3718ccd2a6 remove support of symbols on classify and camelize 2011-09-08 10:22:21 +02:00
Brian Cardarella
6ef1079e0e Reset @dirty to false when slicing an instance of SafeBuffer 2011-07-29 13:10:31 -04:00
Vishnu Atrai
db34a65277 remove unused variables warnings removed 2011-07-26 23:53:54 +05:30
Arun Agrawal
deb60a738c Using slice for instead of gsub to pass with 1.8.7 2011-06-23 18:17:37 +05:30
Damien Mathieu
9fadf385d8 calling unsafe methods which don't return a string shouldn't fail 2011-06-22 15:26:21 +02:00
José Valim
f44db45c87 safe_concat should not work on dirty buffers. 2011-06-16 17:04:31 -03:00
José Valim
594603b45f Fix safe buffer by adding a dirty status. 2011-06-16 16:49:41 -03:00
Michael Koziarski
1300c03477 Ensure that the strings returned by SafeBuffer#gsub and friends aren't considered html_safe?
Also make sure that the versions of those methods which modify a string in place such as gsub! can't be called on safe buffers at all.

Conflicts:

	activesupport/test/safe_buffer_test.rb
2011-06-07 17:02:48 -07:00
Aaron Patterson
c87fb22a06 make sure we play nicely when syck is activated 2011-01-28 15:00:52 -08:00
Santiago Pastorino
1adfb92135 Deleted all references to ActionView::SafeBuffer in favor of ActiveSupport::SafeBuffer
Signed-off-by: Yehuda Katz <wycats@Yehuda-Katz.local>
2010-01-31 22:14:18 -08:00