# zeta2: Make \`new_text\`/\`old_text\` parsing more robust \(\#42997\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/bf0dd4057ce262f6213a685fb73ae5239494673b)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: bf0dd4057ce262f6213a685fb73ae5239494673b

Requested commit: bf0dd4057ce262f6213a685fb73ae5239494673b

Commit: bf0dd4057ce262f6213a685fb73ae5239494673b

Tree: 7b9dd0e59870afa2ec2c08f09493e4563b255322

Author: Ben Kunkle

Committer: GitHub

## Message

````
zeta2: Make `new_text`/`old_text` parsing more robust (#42997)

Closes #ISSUE

The model often uses the wrong closing tag, or has spaces around the
closing tag name. This PR makes it so that opening tags are treated as
authoritative and any closing tag with the name `new_text` `old_text` or
`edits` is accepted based on depth. This has the additional benefit that
the parsing is more robust with contents that contain `new_text`
`old_text` or `edits. I.e. the following test passes

```rust
    #[test]
    fn test_extract_xml_edits_with_conflicting_content() {
        let input = indoc! {r#"
            <edits path="component.tsx">
            <old_text>
            <new_text></new_text>
            </old_text>
            <new_text>
            <old_text></old_text>
            </new_text>
            </edits>
        "#};

        let result = extract_xml_replacements(input).unwrap();
        assert_eq!(result.file_path, "component.tsx");
        assert_eq!(result.replacements.len(), 1);
        assert_eq!(result.replacements[0].0, "<new_text></new_text>");
        assert_eq!(result.replacements[0].1, "<old_text></old_text>");
    }
```

Release Notes:

- N/A *or* Added/Fixed/Improved ...
````

## Parents

- [3c4ca3f37205c51704801b6dbb027493e0167d4e](https://git.cafe/gitcafe/zed/commit/3c4ca3f37205c51704801b6dbb027493e0167d4e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/bf0dd4057ce262f6213a685fb73ae5239494673b?format=markdown)
