Skip to content

Commit

Permalink
Fix Markdown hanging forever (#2513)
Browse files Browse the repository at this point in the history
* Fix issue in SwiftyMardown hanging forever

* Fix removePublicDeclarations.sh curly braces issue

* Add tests to cover for edge case

* Update CHANGELOG
  • Loading branch information
polqf authored Feb 27, 2023
1 parent 171331a commit c5bc1e7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## StreamChat
### 🔄 Changed
- Remove [URLQueryItem] public conformance of ExpressibleByDictionaryLiteral [#2505](https://github.com/GetStream/stream-chat-swift/pull/2505)

### 🐞 Fixed
- Fix messages appearing sooner in Thread pagination [#2470](https://github.com/GetStream/stream-chat-swift/pull/2470)
- Fix messages disappearing from the Message List when quoting a message [#2470](https://github.com/GetStream/stream-chat-swift/pull/2470)
- Fix Markdown formatting hanging with edge case pattern [#2513](https://github.com/GetStream/stream-chat-swift/pull/2513)

# [4.27.1](https://github.com/GetStream/stream-chat-swift/releases/tag/4.27.1)
_February 20, 2023_
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ update_dependencies:
echo "👉 Updating SwiftyGif"
make update_swiftygif version=5.4.2
echo "👉 Updating SwiftyMarkdown"
make update_swiftymarkdown version=1.2.4
make update_swiftymarkdown version=master
echo "👉 Updating DifferenceKit"
make update_differencekit version=1.3.0

Expand Down
6 changes: 2 additions & 4 deletions Scripts/removePublicDeclarations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ do
'public func isContentEqual(to source: Wrapped?) -> Bool {' \
$f

# This replacement is not actually working, and I don't know why,
# for now, I did this change manually.
replaceDeclaration 'func isContentEqual(to source: [Element]) -> Bool' \
'public func isContentEqual(to source: [Element]) -> Bool' \
replaceDeclaration 'func isContentEqual(to source: \[Element\]) -> Bool' \
'public func isContentEqual(to source: \[Element\]) -> Bool' \
$f

replaceDeclaration 'extension ContentIdentifiable where Self: Hashable {' \
Expand Down
2 changes: 1 addition & 1 deletion Scripts/updateDependency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ elif [[ $dependency_directory == *"SwiftyGif"* ]]; then
elif [[ $dependency_directory == *"Starscream"* ]]; then
dependency_url="[email protected]:daltoniam/Starscream.git"
elif [[ $dependency_directory == *"SwiftyMarkdown"* ]]; then
dependency_url="[email protected]:SimonFairbairn/SwiftyMarkdown.git"
dependency_url="[email protected]:GetStream/SwiftyMarkdown.git"
elif [[ $dependency_directory == *"DifferenceKit"* ]]; then
dependency_url="[email protected]:ra1028/DifferenceKit.git"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,27 @@ class SwiftyScanner {
} else {
var remainingTags = min(openRange.upperBound - openRange.lowerBound, closeRange.upperBound - closeRange.lowerBound) + 1
while remainingTags > 0 {
if remainingTags >= self.rule.maxTags {
let shouldAppendStyle = remainingTags >= self.rule.maxTags
if shouldAppendStyle {
remainingTags -= self.rule.maxTags
if let style = self.rule.styles[ self.rule.maxTags ] {
if !styles.contains(where: { $0.isEqualTo(style)}) {
styles.append(style)
}
}
}
if let style = self.rule.styles[remainingTags] {

let remainingTagsStyle = self.rule.styles[remainingTags]
if let style = remainingTagsStyle {
remainingTags -= remainingTags
if !styles.contains(where: { $0.isEqualTo(style)}) {
styles.append(style)
}
}

if !shouldAppendStyle && remainingTagsStyle == nil {
break
}
}

for idx in (openRange.upperBound)...(closeRange.lowerBound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,10 @@ final class DefaultMarkdownFormatter_Tests: XCTestCase {
}
}
}

func test_complexMarkdownPattern_doesNotHangForever() {
let string = "**~*~~~*~*~**~*~* h e a r d ***~*~*~**~*~~~*"
let result = sut.format(string)
XCTAssertEqual(result.string, "**~~*~**~~ h e a r d ***~~~**~")
}
}

0 comments on commit c5bc1e7

Please sign in to comment.