diff --git a/CHANGELOG.md b/CHANGELOG.md index 79da255b..b91cb3a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Collapsed definitions for single-character spinners, to save memory and reduce import time. - Fix print_json indent type in __init__.py - Fix error when inspecting object defined in REPL https://github.com/Textualize/rich/pull/2037 +- Fix incorrect highlighting of non-indented JSON https://github.com/Textualize/rich/pull/2038 ### Changed diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py index a3fe2b05..a34334e3 100644 --- a/tests/test_highlighter.py +++ b/tests/test_highlighter.py @@ -113,6 +113,22 @@ def test_highlight_json_with_indent(): ] +def test_highlight_json_string_only(): + json_string = '"abc"' + text = Text(json_string) + highlighter = JSONHighlighter() + highlighter.highlight(text) + assert text.spans == [Span(0, 5, "json.str")] + + +def test_highlight_json_empty_string_only(): + json_string = '""' + text = Text(json_string) + highlighter = JSONHighlighter() + highlighter.highlight(text) + assert text.spans == [Span(0, 2, "json.str")] + + def test_highlight_json_no_indent(): json_string = json.dumps({"name": "apple", "count": 1}, indent=None) text = Text(json_string)