From 5a354ea9f4d307053cbe2d41dc8b1774f6d9f0e5 Mon Sep 17 00:00:00 2001 From: arihantlodha-cmd Date: Wed, 5 Aug 2026 18:18:51 +0900 Subject: [PATCH] Fix unescaped backslash in theta replacement-rate label Closes #1015. The 'theta' label in model_variables.json used a single backslash ($\theta_j$), which JSON parses into a tab character, so the label failed to render properly in plots. Escape it ($\\theta_j$) to match the already-corrected \\tilde labels. Adds test_constants.py guarding against control characters in any VAR_LABELS/ToGDP_LABELS entry. --- ogcore/model_variables.json | 2 +- tests/test_constants.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/test_constants.py diff --git a/ogcore/model_variables.json b/ogcore/model_variables.json index 6c26cee6a..a6745d377 100644 --- a/ogcore/model_variables.json +++ b/ogcore/model_variables.json @@ -527,7 +527,7 @@ "type": "array-like", "TPI dimensions": "", "SS dimensions": "J", - "label": "Replacement rate ($\theta_j$)", + "label": "Replacement rate ($\\theta_j$)", "toGDP_label": "" }, "factor": { diff --git a/tests/test_constants.py b/tests/test_constants.py new file mode 100644 index 000000000..2350d3b6d --- /dev/null +++ b/tests/test_constants.py @@ -0,0 +1,25 @@ +""" +Tests of constants.py module and the label metadata loaded from +model_variables.json. +""" + +from ogcore import constants + + +def test_labels_have_no_control_characters(): + r""" + Guard against LaTeX label strings in model_variables.json being + written with a single backslash (e.g. "$\theta$"), which JSON parses + into a control character (a tab, in the case of "\t") and which then + fails to render in plots. Backslashes must be escaped ("$\\theta$"). + """ + control_chars = set("\t\r\n\x08\x0c\x0b") + for label_map in (constants.VAR_LABELS, constants.ToGDP_LABELS): + for key, label in label_map.items(): + assert isinstance(label, str) + bad = control_chars.intersection(label) + assert not bad, ( + f"Label for {key!r} contains control character(s) " + f"{[c.encode('unicode_escape').decode() for c in bad]}: " + f"{label!r}. Escape backslashes in model_variables.json." + )