Opened 10 years ago

Closed 9 years ago

#12163 closed enhancement (duplicate)

MIME sniffing can't reliably detect html vs xhtml

Reported by: haiqu Owned by: pulkomandy
Priority: normal Milestone: Unscheduled
Component: Applications/WebPositive Version: R1/Development
Keywords: Cc:
Blocked By: #11800 Blocking:
Platform: All

Description

The following snippet of code shows an error in WebPositive:

<div id="project-header">
  <a href="/"><img src="/home/furius-logo-w.png" id="logo"></a>
  <div id="project-home"><a href="..">Project Home</a></div>
</div>

It will fail to display and throw an error at the second line. Replacing it with the following code works:

<div id="project-header">
  <a href="/"><img src="/home/furius-logo-w.png" id="logo"></img></a>
  <div id="project-home"><a href="..">Project Home</a></div>
</div>

but since the img tag is assymetrical the code itself is wrong.

Change History (6)

comment:1 by pulkomandy, 10 years ago

"an error" isn't very descriptive of what you get. Let me grab my crystal ball...

I think you get a parse error because Web+ detected your file or page as xhtml and you are trying to write html. For remote files Web+ will use the mime type given in the HTTP headers. For local files it will use the mimetype attribute of the file. That attribute is set by the mime sniffing rules (you can see them in preferences/filetypes), but the detection is not perfect and will sometimes mistake html for xhtml. You can manually adjust the attribute (use listattr, catattr, and setattr in terminal to experiment with attributes) and set the correct mime type.

Correct code in xhtml could be (notice the / at the end to close the img):

<img src="/home/furius-logo-w.png" id="logo"/>

comment:2 by haiqu, 10 years ago

It wasn't a very descriptive error message.

error on line 13 at column 64: Opening and ending tag mismatch: img line 0 and a

Here's the head code. The file was machine generated:

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="Docutils 0.8.1: http://docutils.sourceforge.net/" />
<title>Version Control Tools and Other Utilities</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>

It was opened locally. Hope all that helps to understand if it's a bug.

comment:3 by waddlesplash, 9 years ago

Resolution: invalid
Status: newclosed

PulkoMandy is correct, that's invalid XHTML. You have to close the <img> tag for it to be valid XHTML.

comment:4 by haiqu, 9 years ago

Since it's html that's irrelevant.

Note: Content="text/html"

Sheesh.

comment:5 by pulkomandy, 9 years ago

Resolution: invalid
Status: closedreopened
Summary: WebPositive error on img tag between <a></a> tagsMIME sniffing can't reliably detect html vs xhtml
Type: bugenhancement

but there is an XML header and a doctype saying xhtml transitional. So, this pretends to be an XML file. Only when you start to parse it and encounter the meta tag, you should switch to html (and probably start parsing from the start again?).

So, you can force the MIME type of the file to "text/html" using the addattr command.

I'm switching the ticket to enhancement and changing the description. I'm not sure what we can do to improve our sniffing system, it's based on simple rules to be reasonably fast, and XHTML and HTML may simply be too similar to hope reasonably telling them apart, especially in cases like your example.

comment:6 by pulkomandy, 9 years ago

Blocked By: 11800 added
Resolution: duplicate
Status: reopenedclosed
Note: See TracTickets for help on using tickets.