Skip to content

fix(tokenizer): RegexTokenizer._tokenize 빈 문자열 입력 시 IndexError #283

Description

@lovit

문제

_tokenize에 빈 문자열 또는 공백만 있는 문자열이 들어오면 words[0]에서 IndexError가 발생한다.

# tokenizer.py line 146-147
words = self.doublewhite_pattern.sub(" ", s).strip().split()
r = len(words[0])   # words == [] 이면 IndexError ❌

발생 조건

  • _tokenize를 직접 호출할 때 빈 문자열 전달
  • 모든 파이프라인 패턴이 매칭에 실패하고, 원본 문자열이 공백만으로 구성된 경우

수정 방향

words가 비어 있으면 빈 리스트를 반환하는 가드 추가:

if not words:
    return []

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions