Skip to content

String: Convert To Title Case fails with bad error message if exclude contains invalid regexp #5648

@007bsd

Description

@007bsd

Summary

When exclude contains an invalid regex pattern, convert_to_title_case raises a raw re.error instead of a proper ValueError or DataError.

Version

Robot Framework 7.4.2,
Python 3.12

Reproduce

Python:

from robot.libraries.String import String
s = String()
s.convert_to_title_case("hello", exclude="[")
# re.error: unterminated character set at position 0

Robot:

*** Settings ***
Library    String

*** Test Cases ***
Convert To Title Case with invalid regex in exclude
    [Documentation]    Bug: re.error raised instead of ValueError/DataError for invalid regex in exclude
    Convert To Title Case    hello    [

Expected

A ValueError or DataError with a clear message, e.g.:
Invalid exclude pattern '[': unterminated character set

Actual

re.error: unterminated character set at position 0

Location

src/robot/libraries/String.py line 157 — the re.compile(exclude) call is not wrapped in a try/except.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions