Skip to content

Web Component: toggling toolbar decodes escapes in user-entered Markdown #123

Description

@maxmin-es

I am looking to incorporate overtype to a website I'm building, and in doing so Codex brought a bug to my attention that looks legit to me. Below is the bug report it wrote for me:

Changing the Web Component's toolbar setting can modify user-entered Markdown. Reproduced with the unmodified overtype@2.4.2/dist/overtype-webcomponent.min.js bundle in Chrome, without a framework or HTMX.

Reproduction

  1. Create an <overtype-editor toolbar></overtype-editor> and load the Web Component bundle.
  2. Type or paste this Markdown into the editor:
```python
print("\n")
```
  1. Remove the toolbar attribute:
const el = document.querySelector('overtype-editor');
const before = el.getValue();
el.removeAttribute('toolbar');
const after = el.getValue();
console.log(before === after); // false

The literal backslash-n inside the Python string becomes an actual newline. The editor's stored Markdown now contains:

```python
print("
")
```

Expected: changing a display setting preserves the current Markdown exactly.

Cause and proposed fix

The component mirrors edits into its value attribute verbatim in _handleChange / _updateValueAttribute. Changing toolbar calls _reinitializeEditor, which initializes again from that attribute and runs _decodeValue. This decodes user-entered \n, \r, and \t sequences a second time. Statistics and auto-resize changes use the same rebuild path.

Component source

Decoding escapes in an explicitly supplied HTML value attribute is documented behavior and should remain supported. Rather than disabling decoding, could _reinitializeEditor pass its captured currentValue directly to initialization as an already-decoded value, overriding the attribute-derived value before the new editor is constructed? Use an explicit sentinel such as undefined so an empty document is preserved too.

Suggested regression tests:

  • Initial HTML value and explicit subsequent value attribute updates still decode escapes as documented.
  • User-entered literal \n, \r, and \t survive repeated toolbar, statistics, and auto-resize toggles unchanged.
  • Empty content remains empty after those toggles.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions