Carriage Return characters (\r) are incorrectly replaced with Newline characters (\n)
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript
- Lĩnh vực
- backend
Hướng nghiên cứu
Bắt đầu trong src/xmlparser/OrderedObjParser.js tại hàm parseXml và kiểm tra việc chuẩn hóa ký tự xuống dòng. Tái hiện vấn đề bằng XML CDATA được nêu trong báo cáo, sau đó xác minh rằng văn bản đã được phân tích cú pháp vẫn giữ các ký tự \r như mong đợi mà không thay đổi các hành vi đầu vào khác đã được ghi chép.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- Are you running the latest version?
- Have you included sample input, output, error, and expected output?
- Have you checked if you are using correct configuration?
- Did you try online tool?
Description
Carriage Return characters (\r) found within parsed XML are incorrectly converted to newline characters (\n).
I did a quick scan of the source code and found a likely culprit:
const parseXml = function(xmlData) {
xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line
That pretty clearly replaces any \r character (and possibly \r\n pair) with \n.
The online tool does not exhibit this issue because browser node access APIs encode Carriage Return "strings" (the character \ followed by r) as \\r. The regular expression no longer matches. See:
> "1) \r 2) \\r 3) \n 4) \\n 5) \r\n 6) \\r\\n".replace(/\r\n?/g, "\n")
'1) \n 2) \\r 3) \n 4) \\n 5) \n 6) \\r\\n'
Input
The XML that exhibits this issue is of the form:
<properties object="" engine="">
<property type="string" name="x" state="changed">
<![CDATA[This is a carriage return \r...]]>
</property>
<property type="string" name="y" state="changed">
<![CDATA[\r]]>
</property>
</properties>
Code
The code is pretty straightforward.
const XML_OPTIONS_NO_TAG_PARSE: fastXMLParser.X2jOptionsOptional = {
attributeNamePrefix: "@",
ignoreAttributes: false,
parseAttributeValue: false,
parseTagValue: false,
textNodeName: "#value",
};
const XML_PARSER_NO_TAG_PARSE = new fastXMLParser.XMLParser(XML_OPTIONS_NO_TAG_PARSE);
// ...
const parsed = XML_PARSER_NO_TAG_PARSE.parse(xmlData);
After that code runs, the parsed text node content has \n instead of the expected \r.
Output
Running the above results in the following JSON:
{
"properties": {
"property": [
{
"#value": "This is a carriage return \n...",
"@type": "string",
"@name": "x",
"@state": "changed"
},
{
"#value": "\n",
"@type": "string",
"@name": "y",
"@state": "changed"
},
],
"@object": "",
"@engine": ""
}
}
Expected Data
I expect the following output:
{
"properties": {
"property": [
{
"#value": "This is a carriage return \r...",
"@type": "string",
"@name": "x",
"@state": "changed"
},
{
"#value": "\r",
"@type": "string",
"@name": "y",
"@state": "changed"
},
],
"@object": "",
"@engine": ""
}
}
Would you like to work on this issue?
- Yes
- No
- Ngôn ngữ chính
- JavaScript
- Star
- 3.1k
- Fork
- 398
- Merge trung bình
- 3 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NaturalIntelligence/fast-xml-parser
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
ignoreDeclaration does not ignore lower case doctype declarationCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NaturalIntelligence/fast-xml-parser#870 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
CLI crashes with an uncaught exception when the input file is missingCó thể đã có người làm @troclaux đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
NaturalIntelligence/fast-xml-parser#894 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Numeric character references (A, A) are not decoded unless htmlEntities is enabledCó thể đã có người làm @guocn đã nhận 3 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
NaturalIntelligence/fast-xml-parser#892 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của NaturalIntelligence/fast-xml-parser
Issue tương tự
-
Plaid sync fails and rolls back when a removed pending transaction was matched by a bank ruleĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bigcapitalhq/bigcapital#1544 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
help wanted kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
meshery/meshery.io#3112 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area:docs type:chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
bulkhead-labs/tailsuite#31 ·
-
dependencies javascript
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
gems-uff/noworkflow#470 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
product / auth product / console product / sites product / storage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày