Skip to content

Commit e10c666

Browse files
committed
Normalize line breaks for consistency with SQL
The data from the webpage gets submitted with CRLFs (`\r\n`). When this is submitted to a SQL XML column, however, the carriage return (`\r`) gets stripped. As such, when comparing the `AttributeBindingModel.Value` to the `AttributeRecord.Value`, these will never match if the content contains line breaks—_even if the text hasn't been modified_. As a result, any page with e.g. an `HtmlAttribute` will always be marked `IsDirty()`, and always be `Save()`d. The `UpdatedTopic` stored procedure is smart enough to deduplicate the `ExtendedAttributes` field, but this still results in an orphaned version getting created due to the `LastModified` and `LastModifiedBy` fields being introduced. This update normalizes the line breaks by first cleaning the `AttributeBindingModel.Value` to remove carriage returns (`\r`), thus standardizing it with the value in `AttributeRecord.Value`. As a result, a true apples to apples comparison can be made. It's unclear when this issue was introduced. Regardless, this resolves #48.
1 parent f354499 commit e10c666

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

OnTopic.Editor.AspNetCore/Controllers/EditorController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ public async Task<IActionResult> Edit(
444444
topic.Attributes.SetValue(attribute.Key, attribute.DefaultValue);
445445
}
446446
else {
447-
topic.Attributes.SetValue(attribute.Key, attributeValue.Value);
447+
var value = attributeValue.Value?.Replace("\r\n", "\n", StringComparison.Ordinal);
448+
topic.Attributes.SetValue(attribute.Key, value);
448449
}
449450

450451
}

0 commit comments

Comments
 (0)