mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) 5fec930832
, 1a06bee027
: [Backport #20992]
[Bug #20992] Test for local variable name encodings Do not intern invalid symbols in eval parse When the inner code cannot represent the name of the locals in the outer code, do not bother putting them into the constant pool as they will not be referenced. Fixes [Bug #20992] Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
This commit is contained in:
parent
82f7cb7941
commit
698f808cc7
3 changed files with 18 additions and 1 deletions
|
@ -425,6 +425,13 @@ class TestVariable < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_local_variables_encoding
|
||||
α = 1
|
||||
b = binding
|
||||
b.eval("".encode("us-ascii"))
|
||||
assert_equal(%i[α b], b.local_variables)
|
||||
end
|
||||
|
||||
private
|
||||
def with_kwargs_11(v1:, v2:, v3:, v4:, v5:, v6:, v7:, v8:, v9:, v10:, v11:)
|
||||
local_variables
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 1
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 6
|
||||
#define RUBY_PATCHLEVEL 7
|
||||
|
||||
#include "ruby/version.h"
|
||||
#include "ruby/internal/abi.h"
|
||||
|
|
10
vm_eval.c
10
vm_eval.c
|
@ -1690,6 +1690,8 @@ pm_eval_make_iseq(VALUE src, VALUE fname, int line,
|
|||
// scopes array refer to root nodes on the tree, and higher indexes are the
|
||||
// leaf nodes.
|
||||
iseq = parent;
|
||||
rb_encoding *encoding = rb_enc_get(src);
|
||||
|
||||
for (int scopes_index = 0; scopes_index < scopes_count; scopes_index++) {
|
||||
VALUE iseq_value = (VALUE)iseq;
|
||||
int locals_count = ISEQ_BODY(iseq)->local_table_size;
|
||||
|
@ -1711,6 +1713,14 @@ pm_eval_make_iseq(VALUE src, VALUE fname, int line,
|
|||
continue;
|
||||
}
|
||||
|
||||
// Check here if this local can be represented validly in the
|
||||
// encoding of the source string. If it _cannot_, then it should
|
||||
// not be added to the constant pool as it would not be able to
|
||||
// be referenced anyway.
|
||||
if (rb_enc_str_coderange_scan(name_obj, encoding) == ENC_CODERANGE_BROKEN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* We need to duplicate the string because the Ruby string may
|
||||
* be embedded so compaction could move the string and the pointer
|
||||
* will change. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue