Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/sync_default_gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
with:
token: ${{ github.repository == 'ruby/ruby' && secrets.MATZBOT_AUTO_UPDATE_TOKEN || secrets.GITHUB_TOKEN }}

- uses: ruby/setup-ruby@ab177d40ee5483edb974554986f56b33477e21d0 # v1.265.0
with:
ruby-version: '3.4'
bundler: none

- name: Run tool/sync_default_gems.rb
id: sync
run: |
Expand Down
1 change: 1 addition & 0 deletions ext/strscan/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
$INCFLAGS << " -I$(top_srcdir)" if $extmk
have_func("onig_region_memsize(NULL)")
have_func("rb_reg_onig_match", "ruby/re.h")
have_func("rb_deprecate_constant")
create_makefile 'strscan'
else
File.write('Makefile', dummy_makefile("").join)
Expand Down
20 changes: 14 additions & 6 deletions ext/strscan/strscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ extern size_t onig_region_memsize(const struct re_registers *regs);

#define STRSCAN_VERSION "3.1.6.dev"


#ifdef HAVE_RB_DEPRECATE_CONSTANT
/* In ruby 3.0, defined but exposed in external headers */
extern void rb_deprecate_constant(VALUE mod, const char *name);
#else
# define rb_deprecate_constant(mod, name) ((void)0)
#endif

/* =======================================================================
Data Type Definitions
======================================================================= */
Expand Down Expand Up @@ -1274,7 +1282,7 @@ static VALUE
strscan_scan_base10_integer(VALUE self)
{
char *ptr;
long len = 0;
long len = 0, remaining_len;
struct strscanner *p;

GET_SCANNER(self, p);
Expand All @@ -1284,7 +1292,7 @@ strscan_scan_base10_integer(VALUE self)

ptr = CURPTR(p);

long remaining_len = S_RESTLEN(p);
remaining_len = S_RESTLEN(p);

if (remaining_len <= 0) {
return Qnil;
Expand All @@ -1311,7 +1319,7 @@ static VALUE
strscan_scan_base16_integer(VALUE self)
{
char *ptr;
long len = 0;
long len = 0, remaining_len;
struct strscanner *p;

GET_SCANNER(self, p);
Expand All @@ -1321,7 +1329,7 @@ strscan_scan_base16_integer(VALUE self)

ptr = CURPTR(p);

long remaining_len = S_RESTLEN(p);
remaining_len = S_RESTLEN(p);

if (remaining_len <= 0) {
return Qnil;
Expand Down Expand Up @@ -1477,7 +1485,6 @@ strscan_eos_p(VALUE self)
* rest?
*
* Returns true if and only if there is more data in the string. See #eos?.
* This method is obsolete; use #eos? instead.
*
* s = StringScanner.new('test string')
* # These two are opposites
Expand Down Expand Up @@ -1605,7 +1612,7 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name
(const unsigned char* )name_end,
regs);
if (num >= 1) {
return num;
return num;
}
}
rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s",
Expand Down Expand Up @@ -2211,6 +2218,7 @@ Init_strscan(void)
ScanError = rb_define_class_under(StringScanner, "Error", rb_eStandardError);
if (!rb_const_defined(rb_cObject, id_scanerr)) {
rb_const_set(rb_cObject, id_scanerr, ScanError);
rb_deprecate_constant(rb_cObject, "ScanError");
}
tmp = rb_str_new2(STRSCAN_VERSION);
rb_obj_freeze(tmp);
Expand Down
3 changes: 2 additions & 1 deletion pathname_builtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ class Pathname
def initialize(path)
unless String === path
path = path.to_path if path.respond_to? :to_path
raise TypeError unless String === path
path = path.to_str if path.respond_to? :to_str
raise TypeError, "Pathname.new requires a String, #to_path or #to_str" unless String === path
end

if path.include?("\0")
Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/library/stringscanner/unscan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
@s.pos.should == pos
end

it "raises a ScanError when the previous match had failed" do
-> { @s.unscan }.should raise_error(ScanError)
-> { @s.scan(/\d/); @s.unscan }.should raise_error(ScanError)
it "raises a StringScanner::Error when the previous match had failed" do
-> { @s.unscan }.should raise_error(StringScanner::Error)
-> { @s.scan(/\d/); @s.unscan }.should raise_error(StringScanner::Error)
end
end
4 changes: 4 additions & 0 deletions test/pathname/test_pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ def test_initialize
assert_equal('a', p1.to_s)
p2 = Pathname.new(p1)
assert_equal(p1, p2)

obj = Object.new
def obj.to_str; "a/b"; end
assert_equal("a/b", Pathname.new(obj).to_s)
end

def test_initialize_nul
Expand Down
2 changes: 1 addition & 1 deletion test/strscan/test_stringscanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def test_unscan
assert_equal({}, s.named_captures)
assert_equal("te", s.scan(/../))
assert_equal(nil, s.scan(/\d/))
assert_raise(ScanError) { s.unscan }
assert_raise(StringScanner::Error) { s.unscan }
end

def test_rest
Expand Down
Loading