Skip to content

Commit

Permalink
Accept some edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshi-takano committed Mar 4, 2020
1 parent bc29a05 commit 802c2c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions OpenGraph/OpenGraphParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ extension OpenGraphParser {

// prepare regular expressions to extract og property and content.
let propertyRegexp = try! NSRegularExpression(
pattern: "\\sproperty=(?:\"|\')og:([a-zA_Z:]+?)(?:\"|\')",
pattern: "\\sproperty=(?:\"|\')*og:([a-zA_Z:]+)(?:\"|\')*",
options: []
)
let contentRegexp = try! NSRegularExpression(
pattern: "\\scontent=\"(.*?)\"",
pattern: "\\scontent=\\\\*?\"(.*?)\\\\*?\"",
options: []
)

Expand All @@ -43,7 +43,7 @@ extension OpenGraphParser {
var contentMatches = contentRegexp.matches(in: metaTag, options: [], range: NSMakeRange(0, metaTag.count))
if contentMatches.first == nil {
let contentRegexp = try! NSRegularExpression(
pattern: "\\scontent='(.*?)'",
pattern: "\\scontent=\\\\*?'(.*?)\\\\*?'",
options: []
)
contentMatches = contentRegexp.matches(in: metaTag, options: [], range: NSMakeRange(0, metaTag.count))
Expand Down
4 changes: 2 additions & 2 deletions Tests/ogp.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html>
<head>
<meta charset='utf-8'>
<meta property="og:title" content=" < It's example.com title > "><meta property="og:type" content="website" />
<meta property="og:url" content="https://www.example.com" />
<meta property=og:title content=" < It's example.com title > "><meta property="og:type" content="website" />
<meta property="og:url" content=\"https://www.example.com\" />

<!-- og property that has an other attributes. -->
<meta id="og-image" property="og:image" content="https://www.example.com/images/example.png" />
Expand Down

0 comments on commit 802c2c8

Please sign in to comment.