Skip to content

Commit

Permalink
Adjust function to extract post ID from a URL to handle both short-fo…
Browse files Browse the repository at this point in the history
…rm and

long-form formatting.
  • Loading branch information
Kinematics committed Aug 1, 2015
1 parent 9ac45ad commit d8330f2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions TallyCore/Adapters/XenForoAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,18 @@ private string GetPostIdFromUrl(string url)
if (url == null)
throw new ArgumentNullException(nameof(url));

// Format: https://forums.sufficientvelocity.com/posts/4062860/
Regex postLinkRegex = new Regex(@"posts/(?<postId>\d+)/");
var m = postLinkRegex.Match(url);
if (m.Success)
return m.Groups["postId"].Value;

// Format: https://forums.sufficientvelocity.com/threads/a-villain-in-a-world-of-heroes.18001/page-109#post-4062860
postLinkRegex = new Regex(@"/page-\d+#post-(?<postId>\d+)");
m = postLinkRegex.Match(url);
if (m.Success)
return m.Groups["postId"].Value;

throw new ArgumentException("Unable to extract post ID from link:\n" + url, nameof(url));
}

Expand Down

0 comments on commit d8330f2

Please sign in to comment.