INNER CODE UNIT · Python

check_string_value

sameerasw/essentials · scripts/validate_strings.py:75

def check_string_value(key, value, is_formatted_attribute):
    """Checks string content for escaping and formatting issues."""
    issues = []

    # 1. Unescaped Single Quotes
    # Single quotes are valid unescaped ONLY if the whole string is enclosed in double quotes "..."
    stripped = value.strip()
    is_double_quoted = len(stripped) >= 2 and stripped.startswith('"') and stripped.endswith('"')

    if not is_double_quoted:
        # Search for unescaped single quotes: ' not preceded by \
        # Ignore \'
        unescaped_single_quotes = re.findall(r"(?<!\\)'", value)
        if unescaped_single_quotes:
            issues.append({
                'type': 'UNESCAPED_SINGLE_QUOTE',
                'msg': "Unescaped single quote (') found. Must be escaped as \\' or enclosed in double quotes.",
                'fixable': True

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…