PreMailer.Net icon indicating copy to clipboard operation
PreMailer.Net copied to clipboard

Link tag with invalid content (resulting on 404) must result in error?

Open reinaldocoelho opened this issue 6 years ago • 2 comments

I need to process some HTML files out of my control, and sometimes I found itens like that <link href='/test/mycss.css'> but without origin or base tag to find the origin of request.

How is the right way to ignore this and process the other content of my HTML? And can we have an config to ignore 404 and remove this content on validate?

I try to create my own base URI to ignore all content but when I set the baseUri on PreMailer this removes the url getting only the base and give the same error.

Follow the simple test:

[TestMethod]
public void ContainsLinkCssElement_NotCssFile()
{
            Uri fullUrl = new Uri("http://localhost");
            string input = @"<html>
	<head>
	<style type='text/css'>p { margin: 0; }</style>
	</head>
	<body>
		<div style='font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000'>
			<div><link rel=""stylesheet"" href=""/myfolder/css/myown.css?v=120410005131"">Test Message</div>
		</div>
	</body>
</html>";
			PreMailer sut = new PreMailer(input, fullUrl);
			sut.MoveCssInline();
}

Follow the proposal who solve my issue (is valid?):

		[TestMethod]
		public void ContainsLinkCssElement_NotCssFile()
		{
            Uri fullUrl = new Uri("http://localhost/mybaseuri/resultalwaysok");
            string input = @"<html>
	<head>
	<style type='text/css'>p { margin: 0; }</style>
	</head>
	<body>
		<div style='font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000'>
			<div><link rel=""stylesheet"" href=""/myfolder/css/myown.css?v=120410005131"">Test Message</div>
		</div>
	</body>
</html>";
			PreMailer sut = new PreMailer(input, fullUrl);
			sut.MoveCssInline();
		}

Thanks.

reinaldocoelho avatar Jul 18 '18 14:07 reinaldocoelho

I just ran into the same issue. One of my customers tried to request an invalid font (https://fonts.googleapis.com/css?family=Segoe) which returns a 400 error and throws an unhandled WebException.

I'm going to submit a pr that handles webexceptions in LinkTagCssSource and adds to the InlineResult.Warnings collection:

"PreMailer.Net is unable to fetch the requested URL: https://fonts.googleapis.com/css?family=Segoe"

robhoward avatar Feb 08 '19 22:02 robhoward