Skip to content

Commit

Permalink
local_variables needs to acquire properly encoded bytes to check thei…
Browse files Browse the repository at this point in the history
…r 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)
enebo committed Jan 24, 2018
1 parent fea43fb commit cee507c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -767,15 +767,16 @@ public static RubyArray local_variables(ThreadContext context, IRubyObject recv)
@JRubyMethod(name = "local_variables", module = true, visibility = PRIVATE, reads = SCOPE)
public static RubyArray local_variables19(ThreadContext context, IRubyObject recv) {
final Ruby runtime = context.runtime;
Set<ByteList> encounteredLocalVariables = new HashSet<>();
Set<RubySymbol> encounteredLocalVariables = new HashSet<>();
RubyArray allLocalVariables = runtime.newArray();
DynamicScope currentScope = context.getCurrentScope();

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

0 comments on commit cee507c

Please sign in to comment.