Giter VIP home page Giter VIP logo

xmlhtml's People

Contributors

23skidoo avatar alexanderkjeldaas avatar andreasabel avatar aslatter avatar cdsmith avatar cydparser avatar galenhuntington avatar gregorycollins avatar hvr avatar imalsogreg avatar jaspervdj avatar mightybyte avatar norm2782 avatar paul-rouse avatar pbv avatar sebastiaanvisser avatar shlevy avatar sol avatar trofi avatar tych0 avatar zenzike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xmlhtml's Issues

HTML comment parsing is too restrictive

HTML comments have the following format:

<!-- foo -->

This is fine, however, the number of - characters used is not correctly specified in Heist. HTML does not make a distinction between and ------>. Any hyphens after the opening two and preceding the ending two are not significant. Heist will throw a parse error in this situation.

(Originally snapframework/heist#61)

HTML entities

parseHTML is mishandling HTML entities in urls. In particular, if a URL contains the string "&centreLon=158" then parseHTML misinterprets the string "&cent" as the HTML entity "¢" and replaces it with the Unicode value for ¢

If you are allowing ampersands in urls because you are not in strict XML mode, then I believe xmlhtml needs to search for a valid terminating semicolon before converting HTML entities. Or ideally it should not convert the entities at all.

0.2.4 fails to build from source on some 32 bit architectures "numericalEscapes : [Failed]"

(maybe it fails on all 32 bit archs)

https://buildd.debian.org/status/package.php?p=haskell-xmlhtml&suite=unstable

test/src/Text/XmlHtml/Tests.hs:20:1: warning: [-Wunused-imports]
    The qualified import of `Text.Blaze.Internal' is redundant
      except perhaps to import instances from `Text.Blaze.Internal'
    To import instances alone, use: import Text.Blaze.Internal()
[6 of 6] Compiling Main             ( test/src/TestSuite.hs, dist-ghc/build/testsuite/testsuite-tmp/Main.o )
Linking dist-ghc/build/testsuite/testsuite ...
touch build-ghc-stamp
. /usr/share/haskell-devscripts/Dh_Haskell.sh && \
check_recipe
Running debian/hlibrary.setup test --builddir=dist-ghc --show-details=direct
Running 1 test suites...
Test suite testsuite: RUNNING...
byteOrderMark          : [OK]
emptyDocument          : [OK]
publicDocType          : [OK]
systemDocType          : [OK]
emptyDocType           : [OK]
dtdInternalScan        : [OK]
textOnly               : [OK]
textWithRefs           : [OK]
untermRef              : [OK]
textWithCDATA          : [OK]
cdataOnly              : [OK]
commentOnly            : [OK]
emptyElement           : [OK]
emptyElement2          : [OK]
elemWithText           : [OK]
xmlDeclXML             : [OK]
procInst               : [OK]
badDoctype1            : [OK]
badDoctype2            : [OK]
badDoctype3            : [OK]
badDoctype4            : [OK]
badDoctype5            : [OK]
tagNames               : [OK]
emptyDocumentHTML      : [OK]
publicDocTypeHTML      : [OK]
systemDocTypeHTML      : [OK]
emptyDocTypeHTML       : [OK]
textOnlyHTML           : [OK]
textWithRefsHTML       : [OK]
textWithCDataHTML      : [OK]
cdataOnlyHTML          : [OK]
commentOnlyHTML        : [OK]
emptyElementHTML       : [OK]
emptyElement2HTML      : [OK]
elemWithTextHTML       : [OK]
xmlDeclHTML            : [OK]
procInstHTML           : [OK]
badDoctype1HTML        : [OK]
badDoctype2HTML        : [OK]
badDoctype3HTML        : [OK]
badDoctype4HTML        : [OK]
badDoctype5HTML        : [OK]
voidElem               : [OK]
caseInsDoctype1        : [OK]
caseInsDoctype2        : [OK]
voidEmptyElem          : [OK]
rawTextElem            : [OK]
endTagCase             : [OK]
hexEntityCap           : [OK]
laxAttrName            : [OK]
badAttrName            : [OK]
emptyAttr              : [OK]
emptyAttr2             : [OK]
unquotedAttr           : [OK]
laxAttrVal             : [OK]
ampersandInText        : [OK]
omitOptionalEnds       : [OK]
omitEndHEAD            : [OK]
omitEndLI              : [OK]
omitEndDT              : [OK]
omitEndDD              : [OK]
omitEndP               : [OK]
omitEndRT              : [OK]
omitEndRP              : [OK]
omitEndOPTGRP          : [OK]
omitEndOPTION          : [OK]
omitEndCOLGRP          : [OK]
omitEndTHEAD           : [OK]
omitEndTBODY           : [OK]
omitEndTFOOT           : [OK]
omitEndTR              : [OK]
omitEndTD              : [OK]
omitEndTH              : [OK]
testNewRefs            : [OK]
errorImplicitClose     : [OK]
weirdScriptThing       : [OK]
renderByteOrderMark    : [OK]
renderByteOrderMarkLE  : [OK]
singleQuoteInSysID     : [OK]
doubleQuoteInSysID     : [OK]
bothQuotesInSysID      : [OK]
doubleQuoteInPubID     : [OK]
doubleDashInComment    : [OK]
trailingDashInComment  : [OK]
renderEmptyText        : [OK]
singleQuoteInAttr      : [OK]
doubleQuoteInAttr      : [OK]
bothQuotesInAttr       : [OK]
ndashEscapesInLatin    : [OK]
smileyEscapesInLatin   : [OK]
numericalEscapes       : [Failed]
numericalEscapes       
hRenderByteOrderMark   : [OK]
hSingleQuoteInSysID    : [OK]
hDoubleQuoteInSysID    : [OK]
hBothQuotesInSysID     : [OK]
hDoubleQuoteInPubID    : [OK]
hDoubleDashInComment   : [OK]
hTrailingDashInComment : [OK]
hRenderEmptyText       : [OK]
hSingleQuoteInAttr     : [OK]
hDoubleQuoteInAttr     : [OK]
hBothQuotesInAttr      : [OK]
renderHTMLVoid         : [OK]
renderHTMLVoid2        : [OK]
renderHTMLRaw          : [OK]
renderHTMLRawMult      : [OK]
renderHTMLRaw2         : [OK]
renderHTMLRaw3         : [OK]
renderHTMLRaw4         : [OK]
renderHTMLEmptyAttr    : [OK]
renderHTMLEmptyAttr2   : [OK]
renderHTMLAmpAttr1     : [OK]
renderHTMLAmpAttr2     : [OK]
renderHTMLAmpAttr3     : [OK]
renderHTMLQVoid        : [OK]
renderHTMLQVoid2       : [OK]
renderHTMLQRaw         : [OK]
renderHTMLQRawMult     : [OK]
renderHTMLQRaw2        : [OK]
renderHTMLQRaw3        : [OK]
renderHTMLQRaw4        : [OK]
compareExternalIDs     : [OK]
compareInternalSubs    : [OK]
compareDoctypes        : [OK]
compareNodes           : [OK]
compareDocuments       : [OK]
compareEncodings       : [OK]
exerciseShows          : [OK]
docNodeAccessors       : [OK]
isTextNodeYes          : [OK]
isTextNodeNo           : [OK]
isTextNodeNo2          : [OK]
isCommentYes           : [OK]
isCommentNo            : [OK]
isCommentNo2           : [OK]
isElementYes           : [OK]
isElementNo            : [OK]
isElementNo2           : [OK]
tagNameElement         : [OK]
tagNameText            : [OK]
tagNameComment         : [OK]
getAttributePresent    : [OK]
getAttributeMissing    : [OK]
getAttributeWrongType  : [OK]
hasAttributePresent    : [OK]
hasAttributeMissing    : [OK]
hasAttributeWrongType  : [OK]
setAttributeNew        : [OK]
setAttributeReplace    : [OK]
setAttributeWrongType  : [OK]
nestedNodeText         : [OK]
childNodesElem         : [OK]
childNodesOther        : [OK]
childElemsTest         : [OK]
childElemsTagTest      : [OK]
childElemTagExists     : [OK]
childElemTagNotExists  : [OK]
childElemTagOther      : [OK]
descNodesElem          : [OK]
descNodesOther         : [OK]
descElemsTest          : [OK]
descElemsTagTest       : [OK]
descElemTagExists      : [OK]
descElemTagDFS         : [OK]
descElemTagNotExists   : [OK]
descElemTagOther       : [OK]
fromNodeAndCurrent     : [OK]
fromNodesAndSiblings   : [OK]
leftSiblings           : [OK]
emptyFromNodes         : [OK]
cursorNEQ              : [OK]
cursorNavigation       : [OK]
cursorSearch           : [OK]
cursorMutation         : [OK]
cursorInsertion        : [OK]
cursorDeletion         : [OK]
blazeTestString        : [OK]
blazeTestText          : [OK]
blazeTestBS            : [OK]
blazeTestPre           : [OK]
blazeTestExternal      : [OK]
blazeTestCustom        : [OK]
blazeTestMulti         : [OK]
blazeTestEmpty         : [OK]
xmlhtml/ibm-not-wf     : [OK]
xmlhtml/ibm-invalid    : [OK]
xmlhtml/ibm-valid      : [OK]
xmlhtml/oasis          : [OK]
xmlhtml/r-ibm-not-wf   : [OK]
xmlhtml/r-ibm-invalid  : [OK]
xmlhtml/r-ibm-valid    : [OK]
xmlhtml/r-oasis        : [OK]
xmlhtml/h-ibm-not-wf   : [OK]
xmlhtml/h-ibm-invalid  : [OK]
xmlhtml/h-ibm-valid    : [OK]
xmlhtml/h-oasis        : [OK]
xmlhtml/hr-ibm-not-wf  : [OK]
xmlhtml/hr-ibm-invalid : [OK]
xmlhtml/hr-ibm-valid   : [OK]
xmlhtml/hr-oasis       : [OK]

         Test Cases    Total        
 Passed  199           199          
 Failed  1             1            
 Total   200           200          
Test suite testsuite: FAIL
Test suite logged to: dist-ghc/test/xmlhtml-0.2.4-testsuite.log
0 of 1 test suites (0 of 1 test cases) passed.
/usr/share/cdbs/1/class/hlibrary.mk:154: recipe for target 'check-ghc-stamp' failed
make: *** [check-ghc-stamp] Error 1
dpkg-buildpackage: error: debian/rules build-arch gave error exit status 2
--------------------------------------------------------------------------------
Build finished at 2017-06-21T09:39:07Z

Finished
--------

parsing of empty attributes is order-dependent

{-# LANGUAGE OverloadedStrings #-} import Text.XmlHtml tree1 = parseHTML "" "<div itemtype='type' itemscope></div>" tree2 = parseHTML "" "<div itemscope itemtype='type'></div>" -- this order fails to parse

ghci session:

*Main> tree1
Right (HtmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [Element {elementTag = "div", elementAttrs = [("itemtype","type"),("itemscope","")], elementChildren = []}]})
*Main> tree2
Left "(line 1, column 16):\nunexpected \"i\"\nexpecting \"=\", \"/\" or \">\""

Inconsistent whitespace treatement

Leading whitespace treatment in xmlhtml is inconsistent.

Consider the following behavior of parseXML (the same happens with parseHTML) where leading whitespace is always dropped, and trailing whitespace is always kept:

> parseXML "x" ""
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = []})
> parseXML "x" " "
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = []})
> parseXML "x" "x"
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x"]})
> parseXML "x" " x"
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x"]})
> parseXML "x" "x "
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x "]})
> parseXML "x" " x "
Right (XmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [TextNode "x "]})

See what happens, however, when the “leading whitespace” comes after some element:

> parseXML "x" "<a/> b "
Right (HtmlDocument {docEncoding = UTF8, docType = Nothing, docContent = [Element {elementTag = "a", elementAttrs = [], elementChildren = []},TextNode " b "]})

These two examples behave differently, and I think the correct behavior is the one from the latter example, since xmlhtml should not be discarding the contents of a text node.

So, my proposal is:

  • Keep the behavior of leading whitespace after an element as it is today.

  • Keep the behavior of trailing whitespace everywhere as it is today.

  • Fix top-level text node parsing so that it doesn't discard leading whitespace.

Heist eating backslashes in HTML attributes

Part of the HTML5 form specification includes the ability to write regular expressions that the field needs to validate against. Unfortunately, if the attribute includes backslashes for escaping, Heist removes them.

From my template (both vanilla HTML and digestive functors input tags, the result is the same):

<dfInput type="tel" ref="phone" required pattern="(((\d(-| ){0,1}){0,1}((\(\d{3}\)(-| ){0,1})|(\d{3}-))\d{3}-\d{4})|(\+?\d{2}((-| )\d{1,8}){1,5}))(( x| ext)\d{1,5}){0,1}" />

The following HTML is generated:

<input type='tel' maxlength='25' required pattern='(((d(-| ){0,1}){0,1}(((d{3})(-| ){0,1})|(d{3}-))d{3}-d{4})|(+?d{2}((-| )d{1,8}){1,5}))(( x| ext)d{1,5}){0,1}' id='form.phone' name='form.phone' value='555-5555' />

I have also tried setting the attribute using splices and the resulting HTML source is identical to the previous sample:

<dfInput type="tel" ref="phone" required pattern="${phone_pattern}" />
phoneSplices = 
    [ ("phone_pattern", callTemplate "/common/forms/fragments/phone_pattern" [])
    , ("phone_tip", callTemplate "/common/forms/fragments/phone_tip" [])
    ]

The contents of /common/forms/fragments/phone_pattern is a single line of text that is the regex pattern from the first sample.

I'm only using callTemplate because I couldn't figure out why the pattern as a string generates this error: lexical error in string/character literal at character 'd' (still fairly new to Haskell)

phoneSplices = 
    [ ("phone_pattern", textSplice "(((\d(-| ){0,1}){0,1}((\(\d{3}\)(-| ){0,1})|(\d{3}-))\d{3}-\d{4})|(\+?\d{2}((-| )\d{1,8}){1,5}))(( x| ext)\d{1,5}){0,1}" [])
    , ("phone_tip", callTemplate "/common/forms/fragments/phone_tip" [])
    ]

Preserving HTML entities

parseHTML parses "&nbsp;" into a text node with the unicode code point for nonbreaking space: [TextNode "\160"]

Is it possible and safe to add a parser that leaves HTML entities like &nbsp; as they are in text nodes? I have a project where xmlhtml is the first stage in a text pipeline spread across different languages/libraries/environments, where it would be more reliable to pass &nbsp; all the way through than to count on the text encoding of the different components.

Preserving HTML entities could make more sense in contexts like heist as well, where the mental model is that heist is stitching together different html fragments. snapframework/heist#37 for instance.

List xmlhtml independently on stackage

Would it be possible to list this package independently on stackage? I believe it was being brought into stackage transitively via snap-server, which in turn comes via websockets-snap listed under @jaspervdj in https://github.com/fpco/stackage/blob/master/build-constraints.yaml. It is therefore missing at the moment from stackage nightly because snap as a whole is not yet GHC 8 compatible. However, xmlhtml builds successfully against the latest nightly, and I have run the tests manually (with the small change in #18).

I could list this package myself on stackage, but it seems better for it to be done by the maintainers. (This can happen without the tweak to the tests, since they are structured in a way which will not run when building stackage.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.