Skip to content

Commit

Permalink
Fixed the bug in YoutubeVideoSanitizer related to not handling iframes
Browse files Browse the repository at this point in the history
with youtube-nocookie host. Added tests for it.
  • Loading branch information
izabelk committed Nov 2, 2016
1 parent e51c806 commit c48e63c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Html2Amp.IntegrationTests/Html2Amp.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
<None Include="TestData\YouTubeVideoSanitizationWithDataParamsAttributes\YouTubeVideoSanitizationWithDataParamsAttributes.out" />
<None Include="TestData\YouTubeVideoSanitizationWithIdAttribute\YouTubeVideoSanitizationWithIdAttribute.in" />
<None Include="TestData\YouTubeVideoSanitizationWithIdAttribute\YouTubeVideoSanitizationWithIdAttribute.out" />
<None Include="TestData\YouTubeVideoSanitizationWithNoCookieHost\YouTubeVideoSanitizationWithNoCookieHost.in" />
<None Include="TestData\YouTubeVideoSanitizationWithNoCookieHost\YouTubeVideoSanitizationWithNoCookieHost.out" />
<None Include="TestData\YouTubeVideoSanitizationWithOtherNotAllowedAttributes\YouTubeVideoSanitizationWithOtherNotAllowedAttributes.in" />
<None Include="TestData\YouTubeVideoSanitizationWithOtherNotAllowedAttributes\YouTubeVideoSanitizationWithOtherNotAllowedAttributes.out" />
<None Include="TestData\YouTubeVideoSanitizationWithoutWidthAndHeight\YouTubeVideoSanitizationWithoutWidthAndHeight.in" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<iframe width="640" height="390"
src="https://www.youtube-nocookie.com/embed/M7lc1UVf-VE"></iframe>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<amp-youtube width="640" height="390"
data-videoid="M7lc1UVf-VE" layout="responsive"></amp-youtube>
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,19 @@ public void YouTubeVideoSanitizationWithChildren()
HtmlAssert.AreEqual(TestDataProvider.GetOutFile(TestName), actualResult);
AmpAssert.IsValidAmp(TestName);
}

[TestMethod]
public void YouTubeVideoSanitizationWithNoCookieHost()
{
// Arrange
const string TestName = "YouTubeVideoSanitizationWithNoCookieHost";

// Act
var actualResult = HtmlTestFileToAmpConverter.Convert(TestName);

// Assert
HtmlAssert.AreEqual(TestDataProvider.GetOutFile(TestName), actualResult);
AmpAssert.IsValidAmp(TestName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,19 @@ public void ReturnTrue_WhenSourceAttributeIsYouTubeDomainAndStartsWithWWW()
// Assert
Assert.IsTrue(actualResult);
}

[TestMethod]
public void ReturnTrue_WhenSourceAttributeIsYouTubeNoCookie()
{
// Arrange
var htmlElement = ElementFactory.CreateIFrame();
htmlElement.Source = "http://www.youtube-nocookie.com/embed/d8fr3AdK_tQ4";

// Act
var actualResult = new YouTubeVideoSanitizer().CanSanitize(htmlElement);

// Assert
Assert.IsTrue(actualResult);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override bool CanSanitize(IElement element)
if (Uri.TryCreate(sourceAttributeValue, UriKind.Absolute, out sourceUri))
{
return sourceUri.LocalPath.StartsWith("/embed/")
&& Regex.IsMatch(sourceUri.Host, @"^(www\.)?youtube\.com$");
&& Regex.IsMatch(sourceUri.Host, @"^(www\.)?youtube(-nocookie)?\.com$");
}

return false;
Expand Down

0 comments on commit c48e63c

Please sign in to comment.