Skip to content

Commit 4379e5d

Browse files
don't automatically transfer the child's source range to a new parent
rdar://136218537
1 parent 2829eef commit 4379e5d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Sources/Markdown/Base/RawMarkup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -196,7 +196,7 @@ final class RawMarkup: ManagedBuffer<RawMarkupHeader, RawMarkup> {
196196

197197
let parsedRange: SourceRange?
198198
if preserveRange {
199-
parsedRange = header.parsedRange ?? newChild.header.parsedRange
199+
parsedRange = header.parsedRange
200200
} else {
201201
parsedRange = newChild.header.parsedRange
202202
}

Tests/MarkdownTests/Interpretive Nodes/AsideTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,27 @@ class AsideTests: XCTestCase {
196196
}
197197
}
198198

199+
/// Ensure that creating block quotes by construction doesn't trip the "loss of source information" assertion
200+
/// by mistakenly gaining source information.
201+
func testConstructedBlockQuoteDoesntChangeRangeSource() throws {
202+
let source = "Note: This is just a paragraph."
203+
let fakeFileLocation = URL(fileURLWithPath: "/path/to/some-file.md")
204+
let document = Document(parsing: source, source: fakeFileLocation)
205+
let paragraph = try XCTUnwrap(document.child(at: 0) as? Paragraph)
206+
207+
// this block quote has no source information, but its children do
208+
let blockQuote = BlockQuote(paragraph)
209+
let aside = try XCTUnwrap(Aside(blockQuote))
210+
211+
let expectedRootDump = """
212+
BlockQuote
213+
└─ Paragraph @/path/to/some-file.md:1:1-/path/to/some-file.md:1:32
214+
└─ Text @/path/to/some-file.md:1:7-/path/to/some-file.md:1:32 "This is just a paragraph."
215+
"""
216+
217+
XCTAssertEqual(expectedRootDump, aside.content[0].root.debugDescription(options: .printSourceLocations))
218+
}
219+
199220
func assertAside(source: String, conversionStrategy: Aside.TagRequirement, expectedKind: Aside.Kind, expectedRootDump: String, file: StaticString = #file, line: UInt = #line) throws {
200221
let fakeFileLocation = URL(fileURLWithPath: "/path/to/some-file.md")
201222
let document = Document(parsing: source, source: fakeFileLocation)

0 commit comments

Comments
 (0)