-
-
Notifications
You must be signed in to change notification settings - Fork 169
Description
I just went to test the fix from #1139 however it's still failing, but this time with a new error:
Uncaught SyntaxError: "" string literal contains an unescaped line break [Temporalpoints_3_style.js:69:77](file:///tmp/qgis2web/qgis2web_2025_06_07-15_34_10_103333/styles/Temporalpoints_3_style.js)
Uncaught ReferenceError: style_Temporalpoints_3 is not defined
<anonymous> file:///tmp/qgis2web/qgis2web_2025_06_07-15_34_10_103333/layers/layers.js:73
The code in question is this:
if (feature.get("\"title\" + '\n' + format_date(\"start\", 'yyyy-MM-dd')
+ coalesce(' → ' + format_date(\"end\", 'yyyy-MM-dd'), ' → Now')") !== null) {
labelText = String(feature.get("\"title\" + '\n' + format_date(\"start\", 'yyyy-MM-dd')
+ coalesce(' → ' + format_date(\"end\", 'yyyy-MM-dd'), ' → Now')"));
}
In #1139 the problem was that the " character wasn't escaped, and changing it to \" fixed the issue. In this problem, it looks to be the same except it is instead the newline character that is not being escaped. So I imagine if you apply a similar fix for #1139 but for newline characters instead (I guess both \r and \n) then it should fix the problem.
I would suggest replacing these characters with spaces rather than trying to escape them, as that will probably be more robust. (Escaping newlines can be difficult depending on where they are used, so replacing them with spaces avoids the problem entirely.)
You can reproduce the problem by editing a layer, going to the label section, and using the formula editor to specify the label. In the formula, split it across multiple lines, like this:
It does not need to be a complicated formula, just something simple like "field1" + "field2" is enough, with a new line near the plus symbol.
You may also want to consider escaping backslashes while you're there, as it looks like the '\n' is not touched. While this is not a problem, if someone were to enter \" into the formula it would get escaped to \\" which will probably break as well. But if the backslash was escaped from \ to \\, then entering \" would come out as \\\" which is acceptable Javascript code when inside a double-quoted string.