Skip to content

Commit

Permalink
Fix detecting of constants with Unicode
Browse files Browse the repository at this point in the history
There's no need to check the characters that follow the initial one,
instead we can assert that a constant simply starts with a capital latin
letter.

Fixes #3382
  • Loading branch information
Yorick Peterse committed Apr 29, 2015
1 parent 2482b09 commit af157db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 2 additions & 7 deletions vm/symbol_table.cpp
Expand Up @@ -16,13 +16,8 @@ namespace rubinius {
SymbolTable::Kind SymbolTable::detect_kind(const char* str, size_t size) {
const char one = str[0];

// A constant begins with an uppercase letter.
if(one >= 'A' && one <= 'Z') {
// Make sure that the rest of it is only alphanumerics
for(size_t i = 1; i < size; i++) {
if((isalnum(str[i]) || str[i] == '_') == false)
return SymbolTable::Normal;
}
// Constants start with A-Z
if(isupper(one)) {
return SymbolTable::Constant;
}

Expand Down
16 changes: 16 additions & 0 deletions vm/test/test_symbol_table.hpp
Expand Up @@ -22,6 +22,22 @@ class TestSymbolTable : public CxxTest::TestSuite, public VMTest {
destroy();
}

void test_detect_kind_with_constant() {
const char *input = "Pettson";

SymbolTable::Kind kind = symbols->detect_kind(input, strlen(input));

TS_ASSERT_EQUALS(kind, SymbolTable::Constant);
}

void test_detect_kind_with_unicode_constant() {
const char *input = "Pettsonλ";

SymbolTable::Kind kind = symbols->detect_kind(input, strlen(input));

TS_ASSERT_EQUALS(kind, SymbolTable::Constant);
}

void test_lookup_with_c_str() {
Object* sym = symbols->lookup(state, std::string("unique"));
TS_ASSERT(sym->symbol_p());
Expand Down

0 comments on commit af157db

Please sign in to comment.