Skip to content

Commit 731ba7b

Browse files
committed
Fix missing closing header boundary check
1 parent 4522bf8 commit 731ba7b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/databricks/labs/lsql/dashboards.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def split(self) -> tuple[str, str]:
168168
if len(splits) == 3:
169169
_, header, content = splits
170170
return header.strip(), content.lstrip()
171-
if len(splits) == 1:
171+
if len(splits) == 2:
172172
logger.warning(f"Parsing {self._path}: Missing closing header boundary.")
173173
return "", self._content
174174

tests/unit/test_dashboards.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,33 @@ def test_markdown_handler_parses_attribute_from_header(tmp_path, attribute):
224224

225225

226226
@pytest.mark.parametrize("horizontal_rule", ["---", "--------"])
227-
def test_markdown_handler_splits_header(tmp_path, horizontal_rule):
227+
def test_markdown_handler_splits_header(tmp_path, caplog, horizontal_rule):
228228
path = tmp_path / "widget.md"
229229
path.write_text(f"{horizontal_rule}\norder: 10\n{horizontal_rule}\n# Description")
230230
handler = MarkdownHandler(path)
231231

232-
header, content = handler.split()
232+
with caplog.at_level(logging.WARNING, logger="databricks.labs.lsql.dashboards"):
233+
header, content = handler.split()
233234

235+
assert "Missing closing header boundary" not in caplog.text
234236
assert header == "order: 10"
235237
assert content == "# Description"
236238

237239

240+
def test_markdown_handler_warns_about_open_ended_header(tmp_path, caplog):
241+
path = tmp_path / "widget.md"
242+
body = "---\norder: 1\n# Description"
243+
path.write_text(body)
244+
handler = MarkdownHandler(path)
245+
246+
with caplog.at_level(logging.WARNING, logger="databricks.labs.lsql.dashboards"):
247+
header, content = handler.split()
248+
249+
assert "Missing closing header boundary." in caplog.text
250+
assert len(header) == 0
251+
assert content == body
252+
253+
238254
def test_widget_metadata_replaces_width_and_height(tmp_path):
239255
path = tmp_path / "test.sql"
240256
path.write_text("SELECT 1")

0 commit comments

Comments
 (0)