Skip to content

roundtripping link with soh control character (U+0001) causes link to disappear #46

Closed
@ChristianMurphy

Description

@ChristianMurphy

Initial checklist

Affected packages and versions

1.2.4

Link to runnable example

https://stackblitz.com/edit/node-58lyzx?file=index.js

Steps to reproduce

import { remark as remarFactory } from 'remark';
import { visit } from 'unist-util-visit';

const remark = remarFactory();

// clean extra attributes that make it hard to see issue
function scrubber(tree) {
  visit(tree, function (node) {
    node.value = undefined;
    node.position = undefined;
    node.spread = undefined;
    node.lang = undefined;
    node.identifier = undefined;
    node.label = undefined;
    node.title = undefined;
    node.url = undefined;
  });
}

const content = `[a](<�>)`;

const originalAst = remark.parse(content);
const newContent = remark.stringify(originalAst);
const newAst = remark.parse(newContent);

scrubber(originalAst);
scrubber(newAst);

console.log(JSON.stringify(originalAst, null, 4));
console.log(JSON.stringify(newAst, null, 4));

results in

{
    "type": "root",
    "children": [
        {
            "type": "paragraph",
            "children": [
                {
                    "type": "link",
                    "children": [
                        {
                            "type": "text"
                        }
                    ]
                }
            ]
        }
    ]
}

then

{
    "type": "root",
    "children": [
        {
            "type": "paragraph",
            "children": [
                {
                    "type": "text"
                }
            ]
        }
    ]
}

Expected behavior

structure of document should remain the same

Actual behavior

link disappeared

Runtime

Node v16

Package manager

npm v7

OS

Linux

Build and bundle tools

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions