Skip to content

Commit

Permalink
fix: Skip validation in Is*Symbol methods
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Oct 23, 2023
1 parent 2fa9f60 commit 2cc46af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 8 additions & 9 deletions bindings/go/scip/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import (
//
// CAUTION: Does not perform full validation of the symbol string's contents.
func IsGlobalSymbol(symbol string) bool {
return !strings.HasPrefix(symbol, "local ")
return !IsLocalSymbol(symbol)
}

// IsLocalSymbol returns true if the symbol is obviously not a global symbol.
//
// CAUTION: Does not perform full validation of the symbol string's contents.
func IsLocalSymbol(symbol string) bool {
return strings.HasPrefix(symbol, "local ")
}

func isSimpleIdentifier(s string) bool {
Expand All @@ -26,14 +33,6 @@ func isSimpleIdentifier(s string) bool {
return true
}

func IsLocalSymbol(symbol string) bool {
if !strings.HasPrefix(symbol, "local ") {
return false
}
suffix := symbol[6:]
return len(suffix) > 0 && isSimpleIdentifier(suffix)
}

func tryParseLocalSymbol(symbol string) (string, error) {
if !strings.HasPrefix(symbol, "local ") {
return "", nil
Expand Down
17 changes: 8 additions & 9 deletions bindings/rust/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ pub enum SymbolError {
///
/// CAUTION: Does not perform full validation of the symbol string's contents.
pub fn is_global_symbol(sym: &str) -> bool {
!sym.starts_with("local ")
!is_local_symbol(sym)
}

pub fn is_simple_identifier(sym: &str) -> bool {
sym.chars().all(|c| c.is_alphanumeric() || c == '$' || c == '+' || c == '-' || c == '_')
/// Returns true if the symbol is obviously not a global symbol.
///
/// CAUTION: Does not perform full validation of the symbol string's contents.
pub fn is_local_symbol(sym: &str) -> bool {
sym.starts_with("local ")
}

pub fn is_local_symbol(sym: &str) -> bool {
if !sym.starts_with("local ") {
return false;
}
let suffix = &sym[6..];
!suffix.is_empty() && is_simple_identifier(suffix)
pub fn is_simple_identifier(sym: &str) -> bool {
sym.chars().all(|c| c.is_alphanumeric() || c == '$' || c == '+' || c == '-' || c == '_')
}

pub fn try_parse_local_symbol(sym: &str) -> Result<Option<&str>, SymbolError> {
Expand Down

0 comments on commit 2cc46af

Please sign in to comment.