Skip to content

fix: ignore falsy values in boolean prop schema #1730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/core/src/api/nodeConversions/blockToNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ function styledTextToNodes<T extends StyleSchema>(
}

if (config.propSchema === "boolean") {
marks.push(schema.mark(style));
if (value) {
marks.push(schema.mark(style));
}
} else if (config.propSchema === "string") {
marks.push(schema.mark(style, { stringValue: value }));
if (value) {
marks.push(schema.mark(style, { stringValue: value }));
}
} else {
throw new UnreachableCaseError(config.propSchema);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div class="bn-block-content" data-content-type="paragraph">
<p class="bn-inline-content">
Text1
<br />
Text2
<br />
Text3
<br />
</p>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>
Text1
<br />
Text2
<br />
Text3
<br />
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Text1\
Text2\
Text3
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"attrs": {
"backgroundColor": "default",
"id": "1",
"textColor": "default",
},
"content": [
{
"attrs": {
"textAlignment": "left",
},
"content": [
{
"text": "Text1",
"type": "text",
},
{
"type": "hardBreak",
},
{
"text": "Text2",
"type": "text",
},
{
"type": "hardBreak",
},
{
"text": "Text3",
"type": "text",
},
{
"type": "hardBreak",
},
],
"type": "paragraph",
},
],
"type": "blockContainer",
},
]
37 changes: 37 additions & 0 deletions tests/src/unit/core/formatConversion/export/exportTestInstances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,43 @@ export const exportTestInstancesBlockNoteHTML: TestInstance<
},
executeTest: testExportBlockNoteHTML,
},
{
testCase: {
name: "malformed/JSON",
content: [
{
// id: UniqueID.options.generateID(),
type: "paragraph",
content: [
{
type: "text",
text: "Text1\n",
styles: {
bold: false,
},
},
{
type: "text",
text: "Text2\n",
styles: {
italic: false,
fontSize: "",
},
},
{
type: "text",
text: "Text3\n",
styles: {
italic: false,
code: false,
},
},
],
},
],
},
executeTest: testExportBlockNoteHTML,
},
];

export const exportTestInstancesHTML: TestInstance<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ export const testExportParseEqualityBlockNoteHTML = async <

const exported = await editor.blocksToFullHTML(testCase.content);

expect(await editor.tryParseHTMLToBlocks(exported)).toStrictEqual(
partialBlocksToBlocksForTesting(editor.schema, testCase.content),
);
if (testCase.name.startsWith("malformed/")) {
// We purposefully are okay with malformed response, we know they won't match
expect(await editor.tryParseHTMLToBlocks(exported)).not.toStrictEqual(
partialBlocksToBlocksForTesting(editor.schema, testCase.content),
);
} else {
expect(await editor.tryParseHTMLToBlocks(exported)).toStrictEqual(
partialBlocksToBlocksForTesting(editor.schema, testCase.content),
);
}
};

export const testExportParseEqualityNodes = async <
Expand Down
Loading