Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"allow": [
"Bash(dotnet test:*)"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ public void YouTubeDoesntEmbedWhenUrlIsForChannel()
Assert.Equal("blah [url=https://www.youtube.com/@sillynonsense]https://www.youtube.com/@sillynonsense[/url] blah", result);
}

[Fact]
public void YouTubeDoesntEmbedWhenUrlIsForPost()
{
var service = GetService();
_settings.AllowImages = true;
var result = service.CleanForumCode("blah https://www.youtube.com/post/Ugkx-hR1fdEJqSWSGTwzpoU4GcT_4ktnY_Qy blah");
Assert.Equal("blah [url=https://www.youtube.com/post/Ugkx-hR1fdEJqSWSGTwzpoU4GcT_4ktnY_Qy]https://www.youtube.com/pos...T_4ktnY_Qy[/url] blah", result);
}

[Fact]
public void YouTubeLinkParsedToLinkWithImagesOff()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ public void YouTubeTagHttpsConvertedToIframe()
Assert.Equal("<p>test test <iframe width=\"456\" height=\"123\" src=\"https://www.youtube.com/embed/NL125lBWYc4\" frameborder=\"0\" allowfullscreen></iframe> test</p>", result);
}

[Fact]
public void YouTubePostUrlParsedAsRegularLink()
{
var service = GetService();
_settings.YouTubeHeight = 123;
_settings.YouTubeWidth = 456;
_settings.AllowImages = true;
var result = service.ForumCodeToHtml("test https://www.youtube.com/post/Ugkx-hR1fdEJqSWSGTwzpoU4GcT_4ktnY_Qy text");
Assert.Equal("<p>test <a href=\"https://www.youtube.com/post/Ugkx-hR1fdEJqSWSGTwzpoU4GcT_4ktnY_Qy\" target=\"_blank\">https://www.youtube.com/pos...T_4ktnY_Qy</a> text</p>", result);
}

[Fact]
public void UrlWithBangParsesCorrectly()
{
Expand Down
4 changes: 3 additions & 1 deletion src/PopForums/Services/TextParsingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TextParsingService(ISettingsManager settingsManager)
private static readonly Regex ProtocolPattern = new Regex(@"(?<![\]""\>=/\w])(((news|(ht|f)tp(s?))\://)[\w\-\*]+(\.[\w\-/~\*]+)*/?)([\w\?=&/;\+%\*\:~,\.\-\$\|@#\(\)])*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex WwwPattern = new Regex(@"(?<!(\]|""|//))(?<=\s|^)(w{3}(\.[\w\-/~\*]+)*/?)([\?\w=&;\+%\*\:~,\-\$\|@#\(\)])*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex EmailPattern = new Regex(@"(?<=\s|\])(?<!(mailto:|""\]))([\w\.\-_']+)@(([\w\-]+\.)+[\w\-]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex YouTubePattern = new Regex(@"(?<![\]""\>=])(((http(s?))\://)[w*\.]*(youtu\.be|youtube\.com+))(?!.*/shorts/)(?!/@)([\w\?=&/;\+%\*\:~,\.\-\$\|@#\(\)])*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex YouTubePattern = new Regex(@"(?<![\]""\>=])(((http(s?))\://)[w*\.]*(youtu\.be|youtube\.com+))(?!.*/shorts/)(?!.*/post/)(?!/@)([\w\?=&/;\+%\*\:~,\.\-\$\|@#\(\)])*", RegexOptions.Compiled | RegexOptions.IgnoreCase);

/// <summary>
/// Converts forum code from the browser to HTML for storage. This method wraps <see cref="CleanForumCode(string)"/> and <see cref="ForumCodeToHtml(string)"/>, and censors the text.
Expand Down Expand Up @@ -403,6 +403,8 @@ private string ParseYouTubeTags(string text)
var uri = new Uri(url);
if (uri.Host.Contains("youtube"))
{
if (string.IsNullOrEmpty(uri.Query))
continue;
var q = uri.Query.Remove(0, 1).Split('&').Where(x => x.Contains("=")).Select(x => new KeyValuePair<string, string>(x.Split('=')[0], x.Split('=')[1]));
var dictionary = q.ToDictionary(pair => pair.Key, pair => pair.Value);
if (dictionary.Any(x => x.Key == "v"))
Expand Down
Loading