Kazuhiro NISHIYAMA
846a6bb60f
[DOC] Fix a typo [ci skip]
2022-06-26 14:17:14 +09:00
Jeremy Evans
596f4b0d3a
Document that Regexp#source does not retain lexer escapes
...
Related to [Feature #18838 ]
2022-06-20 15:56:28 -07:00
Nobuyoshi Nakada
4a6facc2d6
[Feature #18788 ] [DOC] String options to `Regexp.new`
...
Co-Authored-By: Janosch Müller <janosch.mueller@betterplace.org>
2022-06-20 19:35:12 +09:00
Nobuyoshi Nakada
1e9939dae2
[Feature #18788 ] Support options as `String` to `Regexp.new`
...
`Regexp.new` now supports passing the regexp flags not only as an
`Integer`, but also as a `String. Unknown flags raise errors.
2022-06-20 19:35:12 +09:00
Nobuyoshi Nakada
ab2a43265c
Warn suspicious flag to `Regexp.new`
...
Now second argument should be `true`, `false`, `nil` or Integer.
This flag is confused with third argument some times.
2022-06-20 19:35:12 +09:00
Nobuyoshi Nakada
7f8a915715
[DOC] Refine Regexp.new argument descriptions
2022-06-20 18:39:50 +09:00
Nobuyoshi Nakada
914c26eab3
[DOC] Regexp timeout is float or nil
2022-06-20 17:47:44 +09:00
Nobuyoshi Nakada
cd3a5cd0e3
[DOC] Fixed omissions in Regexp.new arguments
2022-06-20 09:26:11 +09:00
Jeremy Evans
ec3542229b
Ignore invalid escapes in regexp comments
...
Invalid escapes are handled at multiple levels. The first level
is in parse.y, so skip invalid unicode escape checks for regexps
in parse.y.
Make rb_reg_preprocess and unescape_nonascii accept the regexp
options. In unescape_nonascii, if the regexp is an extended
regexp, when "#" is encountered, ignore all characters until the
end of line or end of regexp.
Unfortunately, in extended regexps, you can use "#" as a non-comment
character inside a character class, so also parse "[" and "]"
specially for extended regexps, and only skip comments if "#" is
not inside a character class. Handle nested character classes as well.
This issue doesn't just affect extended regexps, it also affects
"(#?" comments inside all regexps. So for those comments, scan
until trailing ")" and ignore content inside.
I'm not sure if there are other corner cases not handled. A
better fix would be to redesign the regexp parser so that it
unescaped during parsing instead of before parsing, so you already
know the current parsing state.
Fixes [Bug #18294 ]
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2022-06-06 13:50:03 -07:00
Burdette Lamar
b41de3a1e8
[DOC] Enhanced RDoc for MatchData ( #5822 )
...
Treats:
#to_s
#named_captures
#string
#inspect
#hash
#==
2022-04-18 18:19:10 -05:00
Burdette Lamar
6db3f7c405
Enhanced RDoc for MatchData ( #5821 )
...
Treats:
#[]
#values_at
2022-04-18 15:52:07 -05:00
Burdette Lamar
86e23529ad
Enhanced RDoc for MatchData ( #5820 )
...
Treats:
#pre_match
#post_match
#to_a
#captures
2022-04-18 14:34:40 -05:00
Burdette Lamar
b074bc3d61
[DOC] Enhanced RDoc for MatchData ( #5819 )
...
Treats:
#begin
#end
#match
#match_length
2022-04-18 13:02:35 -05:00
Burdette Lamar
9d1dd7a9ed
[DOC] Enhanced RDoc for MatchData ( #5818 )
...
Treats:
#regexp
#names
#size
#offset
2022-04-18 11:31:30 -05:00
Burdette Lamar
51ea67698e
[DOC] Enhanced RDoc for Regexp ( #5815 )
...
Treats:
::new
::escape
::try_convert
::union
::last_match
2022-04-18 10:45:29 -05:00
Burdette Lamar
2b4b513ef0
[DOC] Enhanced RDoc for Regexp ( #5812 )
...
Treats:
#fixed_encoding?
#hash
#==
#=~
#match
#match?
Also, in regexp.rdoc:
Changes heading from 'Special Global Variables' to 'Regexp Global Variables'.
Add tiny section 'Regexp Interpolation'.
2022-04-16 15:20:03 -05:00
Burdette Lamar
e021754db0
[DOC] Enhanced RDoc for Regexp ( #5807 )
...
Treats:
#source
#inspect
#to_s
#casefold?
#options
#names
#named_captures
2022-04-15 13:31:15 -05:00
Nobuyoshi Nakada
d8189ed23f
Return only captured range in `MatchData` [Bug #18670 ]
2022-03-31 18:01:15 +09:00
Yusuke Endoh
c499a4c28a
re.c: stop a wrong warning of "flags ignored" on Regexp.new(//)
...
[Bug #18669 ]
2022-03-31 10:07:09 +09:00
Yusuke Endoh
5df2589b64
internal/ractor.h: Added
...
Currently it has only one function prototype.
2022-03-30 16:50:46 +09:00
Yusuke Endoh
2ade40276b
re.c: raise Regexp::TimeoutError instead of RuntimeError
2022-03-30 16:50:46 +09:00
Yusuke Endoh
ce87bb8bd6
re.c: Add `timeout` keyword for Regexp.new and Regexp#timeout
2022-03-30 16:50:46 +09:00
Yusuke Endoh
ffc3b37f96
re.c: Add Regexp.timeout= and Regexp.timeout
...
[Feature #17837 ]
2022-03-30 16:50:46 +09:00
Shugo Maeda
c8817d6a3e
Add String#byteindex, String#byterindex, and MatchData#byteoffset ( #5518 )
...
* Add String#byteindex, String#byterindex, and MatchData#byteoffset [Feature #13110 ]
Co-authored-by: NARUSE, Yui <naruse@airemix.jp>
2022-02-19 19:10:00 +09:00
Shugo Maeda
cda5aee74e
LONG2NUM() should be used for rmatch_offset::{beg,end}
...
https://github.com/ruby/ruby/pull/5518#discussion_r809645406
2022-02-18 22:13:45 +09:00
Nobuyoshi Nakada
16fdc1ff46
[DOC] Fix broken links to literals.rdoc
2022-02-08 01:27:52 +09:00
S-H-GAMELINKS
804a714971
Replace to RBOOL macro
2022-01-17 13:49:37 +09:00
Burdette Lamar
28fb6d6b9e
Adding links to literals and Kernel ( #5192 )
...
* Adding links to literals and Kernel
2021-12-03 07:12:28 -06:00
S.H
dc9112cf10
Using NIL_P macro instead of `== Qnil`
2021-10-03 22:34:45 +09:00
Jeremy Evans
abc0304cb2
Avoid race condition in Regexp#match
...
In certain conditions, Regexp#match could return a MatchData with
missing captures. This seems to require at the least, multiple
threads calling a method that calls the same block/proc/lambda
which calls Regexp#match.
The race condition happens because the MatchData is passed from
indirectly via the backref, and other threads can modify the
backref.
Fix the issue by:
1. Not reusing the existing MatchData from the backref, and always
allocating a new MatchData.
2. Passing the MatchData directly to the caller using a VALUE*,
instead of indirectly through the backref.
It's likely that variants of this issue exist for other Regexp
methods. Anywhere that MatchData is passed implicitly through
the backref is probably vulnerable to this issue.
Fixes [Bug #17507 ]
2021-10-01 19:50:19 -09:00
Nobuyoshi Nakada
f2cb6288bc
[Feature #18172 ] Add MatchData#match_length
...
The method to return the length of the matched substring
corresponding to the given argument.
2021-09-16 19:55:06 +09:00
Nobuyoshi Nakada
09d724e6f8
[Feature #18172 ] Add MatchData#match
...
The method to return the single matched substring corresponding to
the given argument.
2021-09-16 19:55:06 +09:00
S.H
b8c3a84bdd
Refactor and Using RBOOL macro
2021-09-15 08:11:05 +09:00
Nobuyoshi Nakada
c5570a7c11
Extract backref_number_check
2021-09-12 11:16:51 +09:00
Nobuyoshi Nakada
99d8c4832a
Preserve the encoding of the argument in IndexError [Bug #18160 ]
2021-09-12 11:16:51 +09:00
Martin Dürst
f2ffa88964
Show default argument explicitly for Rexexp#match? [ci skip]
2021-09-01 09:37:13 +09:00
Martin Dürst
45b8846bec
Fix minor grammar issue in documentation of Regexp#match? [ci skip]
2021-09-01 09:24:34 +09:00
S.H
378e8cdad6
Using RBOOL macro
2021-08-02 12:06:44 +09:00
Nobuyoshi Nakada
9f3888d6a3
Warn more duplicate literal hash keys
...
Following non-special_const literals:
* T_REGEXP
2021-06-03 15:11:18 +09:00
S.H
d627b75e01
Add static modifier to C function in re.c ( #3153 )
...
* add static modifier for rb_reg_eqq func
* add static modifier for rb_check_regexp_type func
2021-06-01 00:59:33 -07:00
Nobuyoshi Nakada
947d93b715
[DOC] {Array,MatchData}#values_at understand ranges [ci skip]
2021-02-07 10:30:43 +09:00
Marcus Stollsteimer
3108ad7bf3
[DOC] Fix grammar: "is same as" -> "is the same as"
2021-01-05 15:13:53 +01:00
Jeremy Evans
05313c914b
Use category: :deprecated in warnings that are related to deprecation
...
Also document that both :deprecated and :experimental are supported
:category option values.
The locations where warnings were marked as deprecation warnings
was previously reviewed by shyouhei.
Comment a couple locations where deprecation warnings should probably
be used but are not currently used because deprecation warning
enablement has not occurred at the time they are called
(RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K).
Add assert_deprecated_warn to test assertions. Use this to simplify
some tests, and fix failing tests after marking some warnings with
deprecated category.
2020-12-18 09:54:11 -08:00
Nobuyoshi Nakada
85aabef023
[Feature #17136 ] Remove special behavior from $KCODE
2020-11-28 18:51:36 +09:00
Koichi Sasada
7ad56fd87b
freeze dynamic regexp literals
...
Regexp literals are frozen, and also dynamically comppiled Regexp
literals (/#{expr}/) are frozen.
2020-10-27 01:45:57 +09:00
Koichi Sasada
99310e3eb5
Some global variables can be accessed from ractors
...
Some global variables should be used from non-main Ractors.
[Bug #17268 ]
```ruby
# ractor-local (derived from created ractor): debug
'$DEBUG' => $DEBUG,
'$-d' => $-d,
# ractor-local (derived from created ractor): verbose
'$VERBOSE' => $VERBOSE,
'$-w' => $-w,
'$-W' => $-W,
'$-v' => $-v,
# process-local (readonly): other commandline parameters
'$-p' => $-p,
'$-l' => $-l,
'$-a' => $-a,
# process-local (readonly): getpid
'$$' => $$,
# thread local: process result
'$?' => $?,
# scope local: match
'$~' => $~.inspect,
'$&' => $&,
'$`' => $`,
'$\'' => $',
'$+' => $+,
'$1' => $1,
# scope local: last line
'$_' => $_,
# scope local: last backtrace
'$@' => $@,
'$!' => $!,
# ractor local: stdin, out, err
'$stdin' => $stdin.inspect,
'$stdout' => $stdout.inspect,
'$stderr' => $stderr.inspect,
```
2020-10-20 15:38:54 +09:00
Kazuhiro NISHIYAMA
1c138327e0
Try to fix compile error on windows
...
https://github.com/ruby/ruby/runs/1041040167?check_suite_focus=true#step:11:177
```
compiling ../src/re.c
re.c
../src/re.c(317): error C2057: expected constant expression
../src/re.c(317): error C2466: cannot allocate an array of constant size 0
../src/re.c(467): error C2057: expected constant expression
../src/re.c(467): error C2466: cannot allocate an array of constant size 0
../src/re.c(467): error C2133: 'opts': unknown size
../src/re.c(559): error C2057: expected constant expression
../src/re.c(559): error C2466: cannot allocate an array of constant size 0
../src/re.c(559): error C2133: 'optbuf': unknown size
../src/re.c(673): error C2057: expected constant expression
../src/re.c(673): error C2466: cannot allocate an array of constant size 0
../src/re.c(673): error C2133: 'opts': unknown size
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\cl.EXE"' : return code '0x2'
Stop.
```
2020-08-28 22:03:06 +09:00
Nobuyoshi Nakada
75c4e9b72e
Named the magic number for regexp option buffer size
...
In `rb_enc_reg_error_desc`, no longer kcode option is added.
2020-08-28 19:29:16 +09:00
Nobuyoshi Nakada
e658040266
RSTRING_LEN was not used
2020-08-14 16:12:58 +09:00
Yusuke Endoh
4318aba9c9
re.c: prevent "warning: variable 'n' set but not used"
...
by adding MAYBE_UNUSED.
2020-08-14 08:51:14 +09:00