Skip to content

Commit cee507c

Browse files
committedJan 24, 2018
local_variables needs to acquire properly encoded bytes to check their first
and last character to see if it is a local variable. In truth, this is pretty weird code. IdUtils only works with String and without doubling the code for ByteList there is a weakness since non Java Charset strings will not work here. IdUtils itself is also pretty weird since we really just want variables which are not special and this method checks for all sorts of things we know these strings can never be. (FIXME: added)
1 parent fea43fb commit cee507c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
 

‎core/src/main/java/org/jruby/RubyKernel.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,16 @@ public static RubyArray local_variables(ThreadContext context, IRubyObject recv)
767767
@JRubyMethod(name = "local_variables", module = true, visibility = PRIVATE, reads = SCOPE)
768768
public static RubyArray local_variables19(ThreadContext context, IRubyObject recv) {
769769
final Ruby runtime = context.runtime;
770-
Set<ByteList> encounteredLocalVariables = new HashSet<>();
770+
Set<RubySymbol> encounteredLocalVariables = new HashSet<>();
771771
RubyArray allLocalVariables = runtime.newArray();
772772
DynamicScope currentScope = context.getCurrentScope();
773773

774774
while (currentScope != null) {
775-
for (ByteList name : currentScope.getStaticScope().getByteVariables()) {
776-
// FIXME: bytelist_love: Make charsetless checking of isLocal.
775+
for (ByteList rawByteListName : currentScope.getStaticScope().getByteVariables()) {
776+
RubySymbol name = runtime.newSymbol(rawByteListName);
777+
// FIXME: Technically a non-charset String will still not work here.
777778
if (IdUtil.isLocal(name.toString()) && !encounteredLocalVariables.contains(name)) {
778-
allLocalVariables.push(runtime.newSymbol(name));
779+
allLocalVariables.push(name);
779780
encounteredLocalVariables.add(name);
780781
}
781782
}

0 commit comments

Comments
 (0)
Please sign in to comment.