Skip to content

Correct encode text #266

@apronin83

Description

@apronin83

You have incorrect coding of the text of the node and attribute.

Your code (dom.js):

function _xmlEncoder(c){
	return c == '<' && '&lt;' ||
         c == '>' && '&gt;' ||
         c == '&' && '&amp;' ||
         c == '"' && '&quot;' ||
         '&#'+c.charCodeAt()+';'
}

...

	case ATTRIBUTE_NODE:
		return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
	case TEXT_NODE:
		return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));

My code (dom.js):

function _xmlEncoder(c) {
    return c == '<' && '&lt;' ||
        c == '>' && '&gt;' ||
        c == '&' && '&amp;' ||
        c == '"' && '&quot;' ||
        c == "'" && '&apos;';
}

...

	case ATTRIBUTE_NODE:
		return buf.push(' ',node.name,'="',node.value.replace(/[&"<>\']/g,_xmlEncoder),'"');
	case TEXT_NODE:
		return buf.push(node.data.replace(/[&"<>\']/g,_xmlEncoder));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions