Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cfnlint/jsonschema/_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from __future__ import annotations

import json
from copy import deepcopy
from difflib import SequenceMatcher
from typing import Any, Sequence
Expand Down Expand Up @@ -644,7 +645,7 @@ def pattern(
return

if not isinstance(instance, str):
instance = str(instance)
instance = json.dumps(instance)

if not re.search(patrn, instance):
yield ValidationError(f"{instance!r} does not match {patrn!r}")
Expand Down
2 changes: 1 addition & 1 deletion test/unit/module/jsonschema/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def test_validator(name, schema, instance, expected, validator):
),
(
"pattern with bool converts to string",
{"pattern": "^True$"},
{"pattern": "^true$"},
True,
[],
),
Expand Down
8 changes: 8 additions & 0 deletions test/unit/rules/resources/properties/test_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def test_validate(rule, validator):
assert len(errs) == 0


def test_validate_boolean(rule, validator):
# Boolean True stringifies to "true" via json.dumps, matching "true|false"
assert len(list(rule.pattern(validator, "true|false", True, {}))) == 0
assert len(list(rule.pattern(validator, "true|false", False, {}))) == 0
# Boolean should not match an unrelated pattern
assert len(list(rule.pattern(validator, "^foo$", True, {}))) == 1


def test_pattern_exceptions(rule, validator):
rule.configure({"exceptions": ["AWS::"]})

Expand Down
Loading