Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marko drops closing quote around value #1912

Closed
snyamathi opened this issue Mar 14, 2023 · 1 comment · Fixed by marko-js/htmljs-parser#161
Closed

Marko drops closing quote around value #1912

snyamathi opened this issue Mar 14, 2023 · 1 comment · Fixed by marko-js/htmljs-parser#161
Labels
type:unverified bug A bug report that has not been verified

Comments

@snyamathi
Copy link
Contributor

snyamathi commented Mar 14, 2023

Marko Version: 5.24.0

Details

Marko seems to be dropping the closing ' of a quoted attribute value inside a script. See https://github.com/snyamathi/marko-repro/blob/master/template.marko#L6 as a concrete example / reproduction repo.

This seems to be a regression and did not happen until sometime recently. However, it might be something to do with Babel rather than Marko.

$ const foo = "bar"

<script>window.baz='${foo}';</script>

Expected Behavior

It should render

<script>window.baz='bar';</script>

but it instead renders - note the closing ' is missing after 'bar

<script>window.baz='bar;</script>

Possible Fix

Unsure, but this is the compiled Marko template for the above component

// Compiled using marko@5.24.0 - DO NOT EDIT
"use strict";

exports.__esModule = true;
exports.default = void 0;
var _index = require("marko/dist/runtime/html/index.js");
var _renderer = _interopRequireDefault(require("marko/dist/runtime/components/renderer.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const _marko_componentType = "2pyMv7mw",
  _marko_template = (0, _index.t)(_marko_componentType);
_marko_template.path = __filename;
var _default = _marko_template;
exports.default = _default;
const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state, $global) {
  const foo = "bar";
  out.w("<script>window.baz='bar;</script>");
}, {
  t: _marko_componentType,
  i: true
}, _marko_component);
_marko_template.meta = {
  id: _marko_componentType
};

I'm also not sure that the '${foo}' syntax is correct. It works if I use JSON.strinfigy but that removes protection against closing the script tag.

Additional Info

Your Environment

Steps to Reproduce

Clone the following repo and npm start. You'll notice that the markup that comes out of this is invalid and causes an error:

https://github.com/snyamathi/marko-repro/blob/master/template.marko#L6

$ curl localhost:8080
<body>
  <h1>Hello</h1>
  <script>
    window.name = "Frank;
  </script>
  ...

Stack Trace

@snyamathi snyamathi added the type:unverified bug A bug report that has not been verified label Mar 14, 2023
@snyamathi
Copy link
Contributor Author

marko-js/htmljs-parser#158 looks sus - pinning htmljs-parser to 5.4.1 fixes the issue cc @DylanPiercey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:unverified bug A bug report that has not been verified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant