Explorar o código

refactored quoted value test code

Gildas %!s(int64=7) %!d(string=hai) anos
pai
achega
c601c4fd24
Modificáronse 1 ficheiros con 4 adicións e 4 borrados
  1. 4 4
      lib/single-file/serializer.js

+ 4 - 4
lib/single-file/serializer.js

@@ -123,7 +123,7 @@ this.serializer = this.serializer || (() => {
 				value = Array.from(element.classList).map(className => className.trim()).join(" ");
 			}
 			value = value.replace(/&/g, "&").replace(/\u00a0/g, " ").replace(/"/g, """);
-			const validUnquotedValue = value.match(/^[^ \t\n\f\r"'`=<>]+$/);
+			const invalidUnquotedValue = !value.match(/^[^ \t\n\f\r'`=<>]+$/);
 			content += " ";
 			if (!attribute.namespace) {
 				content += name;
@@ -141,11 +141,11 @@ this.serializer = this.serializer || (() => {
 			}
 			if (value != "") {
 				content += "=";
-				if (!validUnquotedValue) {
+				if (invalidUnquotedValue) {
 					content += "\"";
 				}
 				content += value;
-				if (!validUnquotedValue) {
+				if (invalidUnquotedValue) {
 					content += "\"";
 				}
 			}
@@ -154,7 +154,7 @@ this.serializer = this.serializer || (() => {
 	}
 
 	function spaceFirstCharacter(textContent) {
-		return Boolean(textContent.charAt(0).match(/[\u0020\u0009\u000A\u000C\u000D]+/)); // eslint-disable-line no-control-regex
+		return Boolean(textContent.charAt(0).match(/ \t\n\f\r+/));
 	}
 
 })();