8000 Parsing an attribute without a value can cause code confusion · Issue #486 · xmldom/xmldom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Parsing an attribute without a value can cause code confusion #486
Closed
@Bulandent

Description

@Bulandent

Describe the bug

Something went wrong when I parsed the following code。

<template>
  <view>
    <image lazy />
    <image></image>
  </view>
</template>

The above code is parsed into something like this:

<template>
  <view>
    <image lazy="lazy">
    <image/>
  
</image></view></template>

To Reproduce
https://stackblitz.com/edit/js-xmldom-template-cyojup?file=index.js

Expected behavior

<template>
  <view>
    <image lazy="lazy"/>
    <image/>
  </view>
</template>

Runtime & Version:
xmldom version: 0.8.6
runtime version: 0.8.6
other related software and version:

Additional context

I tried to solve the problem myself, until I changed the code in @xmldom/xmldom/lib/sax.js in such a way that it could parse properly。

case '/':
	switch(s){
	case S_TAG:
		el.setTagName(source.slice(start,p));
	case S_ATTR_END:
	case S_TAG_SPACE:
	case S_TAG_CLOSE:
		s =S_TAG_CLOSE;
		el.closed = true;
	case S_ATTR_NOQUOT_VALUE:
	case S_ATTR:
-	// case S_ATTR_SPACE:
		break;
+	case S_ATTR_SPACE:
+		el.closed = true;
+		break;
	//case S_EQ:
	default:
		throw new Error("attribute invalid close char('/')") // No known test case
	}
	break;

Finally, I put up the pull request, I don't know whether my solution is right or not, so you can check it when you are free.
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingxml:not well-formedhttps://www.w3.org/TR/xml11/#dt-wellformed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0