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
38 changes: 38 additions & 0 deletions tests/test_invalid_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,44 @@ def test_dynamic_table_does_not_render_header_fallback_without_rows(self):
assert "<table" not in rendered_html, "Empty tables should not render any table markup"
assert "Created At" not in rendered_html, "Hidden empty columns should not leak into output"

def test_dynamic_table_hides_false_fallback_columns(self):
"""Fallback headers should honor gridState column visibility for all hidden columns."""
data = {
"type": "doc",
"content": [
{
"type": "dynamicTable",
"attrs": {
"columns": {},
"content": {
"headers": ["Source", "Created At", "Description"],
"rows": [
["Vigilance - Trend Reports", "2026-04-22T13:21:57.087000", "Yaaahoooooo"],
],
},
"gridState": {
"columns": {
"columnVisibilityModel": {
"Created At": False,
"Description": False,
},
"orderedFields": ["Created At", "Source", "Description"],
}
},
},
}
],
}

rendered_html = self.doc.render(data)

assert "<th>Source</th>" in rendered_html, "Visible fallback columns should render"
assert "Vigilance - Trend Reports" in rendered_html, "Visible fallback cell values should render"
assert "Created At" not in rendered_html, "Hidden fallback headers should not render"
assert "2026-04-22T13:21:57.087000" not in rendered_html, "Hidden fallback cell values should not render"
assert "Description" not in rendered_html, "Any column hidden in gridState should be omitted"
assert "Yaaahoooooo" not in rendered_html, "Hidden column cells should be omitted"

def test_dynamic_table_security(self):
"""Test security features - dangerous content should be escaped."""
data = {
Expand Down
13 changes: 12 additions & 1 deletion tiptapy/templates/dynamicTable.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{%- set visible_columns = [] -%}
{%- set rows = node.attrs.content.rows if node.attrs.content and node.attrs.content.rows else [] -%}
{%- set grid_columns = node.attrs.gridState.columns if node.attrs.gridState and node.attrs.gridState.columns else {} -%}
{%- set visibility_model = grid_columns.columnVisibilityModel if grid_columns and grid_columns.columnVisibilityModel else {} -%}
{%- set ordered_fields = grid_columns.orderedFields if grid_columns and grid_columns.orderedFields else [] -%}
{%- if rows|length == 0 -%}
No content found
{%- else -%}
Expand All @@ -11,9 +14,17 @@
{%- endif -%}
{%- endfor -%}
{%- elif node.attrs.content and node.attrs.content.headers -%}
{%- for header in node.attrs.content.headers -%}
{%- for header in ordered_fields -%}
{%- if header in node.attrs.content.headers and visibility_model.get(header, True) -%}
{%- set _ = visible_columns.append((header, {"originalName": header, "alias": None, "visible": True, "order":
loop.index0, "width": None})) -%}
{%- endif -%}
{%- endfor -%}
{%- for header in node.attrs.content.headers -%}
{%- if header not in ordered_fields and visibility_model.get(header, True) -%}
{%- set _ = visible_columns.append((header, {"originalName": header, "alias": None, "visible": True, "order":
visible_columns|length, "width": None})) -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
<thead>
Expand Down
13 changes: 12 additions & 1 deletion tiptapy/templates/dynamic_table.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{%- set visible_columns = [] -%}
{%- set rows = node.attrs.content.rows if node.attrs.content and node.attrs.content.rows else [] -%}
{%- set grid_columns = node.attrs.gridState.columns if node.attrs.gridState and node.attrs.gridState.columns else {} -%}
{%- set visibility_model = grid_columns.columnVisibilityModel if grid_columns and grid_columns.columnVisibilityModel else {} -%}
{%- set ordered_fields = grid_columns.orderedFields if grid_columns and grid_columns.orderedFields else [] -%}
{%- if rows|length == 0 -%}
No content found
{%- else -%}
Expand All @@ -11,9 +14,17 @@
{%- endif -%}
{%- endfor -%}
{%- elif node.attrs.content and node.attrs.content.headers -%}
{%- for header in node.attrs.content.headers -%}
{%- for header in ordered_fields -%}
{%- if header in node.attrs.content.headers and visibility_model.get(header, True) -%}
{%- set _ = visible_columns.append((header, {"originalName": header, "alias": None, "visible": True, "order":
loop.index0, "width": None})) -%}
{%- endif -%}
{%- endfor -%}
{%- for header in node.attrs.content.headers -%}
{%- if header not in ordered_fields and visibility_model.get(header, True) -%}
{%- set _ = visible_columns.append((header, {"originalName": header, "alias": None, "visible": True, "order":
visible_columns|length, "width": None})) -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
<thead>
Expand Down