Skip to content

Commit

Permalink
fix: urls with periods after them include the period and don't work a…
Browse files Browse the repository at this point in the history
…s expected #1233
  • Loading branch information
bryanmontz committed Aug 12, 2024
1 parent d529a90 commit 4a7e33f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Fixed an issue where the sheet asking users to set up a NIP-05 username would appear after reinstalling Nos, even if the profile already had a NIP-05 username.
- Fixed a bug where urls with periods after them would include the period.

## [0.1.24] - 2024-08-09Z

Expand Down
2 changes: 1 addition & 1 deletion Nos/Models/URLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct URLParser {
// https://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax,_internationalization

// swiftlint:disable:next line_length
let regexPattern = "(\\s*)(?<url>((https?://){1}|(?<![\\w@.]))([a-zA-Z0-9][-a-zA-Z0-9]{0,62}\\.){1,127}[a-z]{2,63}\\b[-a-zA-Z0-9@:%_\\+.~#?&/=]*)"
let regexPattern = "(\\s*)(?<url>((https?://){1}|(?<![\\w@.]))([a-zA-Z0-9][-a-zA-Z0-9]{0,62}\\.){1,127}[a-z]{2,63}\\b[-a-zA-Z0-9@:%_\\+.~#?&/=]*(?<![.,!?\\)\\]]))"

var urls: [URL] = []
do {
Expand Down
16 changes: 16 additions & 0 deletions NosTests/URLParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ class URLParserTests: XCTestCase {
XCTAssertEqual(actualString, expectedString)
XCTAssertEqual(actualURLs, expectedURLs)
}

func testExtractURLsDoesNotIncludePeriodsInURLs() throws {
// Arrange
let string = "Welcome to nos.social. It's a place for humans"
let expectedString = "Welcome to [nos.social](https://nos.social). It's a place for humans"
let expectedURLs = [
URL(string: "https://nos.social")!
]

// Act
let (actualString, actualURLs) = sut.replaceUnformattedURLs(in: string)

// Assert
XCTAssertEqual(actualString, expectedString)
XCTAssertEqual(actualURLs, expectedURLs)
}

func testExtractURLsWithImage() throws {
let string = "Hello, world!https://cdn.ymaws.com/footprints.jpg"
Expand Down

0 comments on commit 4a7e33f

Please sign in to comment.