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

Escape quotes in value for radio matcher #309

Merged
merged 1 commit into from
Sep 28, 2016

Conversation

jeremywadsack
Copy link
Contributor

Under jQuery 1.12, the provided expression for matching a radio button when the value contains a quote throws a "Syntax error, unrecognized expression".

This resolves that by properly escaping quote characters in the value before building the matching expression.

Note that in order to prove this and build a failing test I fixed up test/index.html to pull in qunit from the vendor folder (it was missing). This is because the phantomjs runner is broken right now in the npm/karma tests. (There's some discussion of this under #307.)

Then I found that this doesn't fail in the bundled jQuery (1.8.3), but does fail with 1.12.x that we are using. I updated the reference in test/index.html to use the version from the jQuery CDN just to make the test show that the code is fixed. I don't know if you want to update the vendored jQuery to the latest from the 1.x branch, but I'm happy to make that change as well.

@y-takey y-takey mentioned this pull request Sep 28, 2016
Copy link
Contributor

@akre54 akre54 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. See my comments


<!--script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.1/zepto.min.js"></script>
<script type="text/javascript" src="vendor/zepto-data.js"></script-->
<script type="text/javascript" src="vendor/jquery.js"></script>
<script type="text/javascript" src="vendor/qunit.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
Copy link
Contributor

@akre54 akre54 Sep 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please keep this as the vendored code so we don't need the internet to run the tests?

<script type="text/javascript" src="vendor/jquery.js"></script>
<script type="text/javascript" src="vendor/qunit.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="vendor/qunit-2.0.1.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this change into another PR. And replace the file in place instead of creating a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. See #311.

@@ -449,7 +449,7 @@
selector: 'input[type="radio"]',
events: ['change'],
update: function($el, val) {
$el.filter('[value="'+val+'"]').prop('checked', true);
$el.filter('[value="'+val.toString().replace(/"/g, '\\"')+'"]').prop('checked', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pull this variable out to the line above. Perhaps with a comment explaining what it is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@jeremywadsack
Copy link
Contributor Author

@akre54 Fixes done. Rebased, squashed, and pushed.

Let me know if there are any other changes that I should look at.

Thanks for the quick response on this!

// Because we use " in the value descriptor, we need to escape any
// quotes in the value itself otherwise jQuery/Sizzle complain that
// the selector is invalid.
escapedVal = val.toString().replace(/"/g, '\\"')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a var before escapedVal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, good catch. Too much coffee script lately.

Fixed, sqaushed, pushed.

Under jQuery 1.12, the provided expression for matching a radio
button when the value containers a quote throws a Syntax error,
unrecognized expression.

This resolves that by properly escaping quote characters in the
value before building the matching expression.
@akre54 akre54 merged commit 780b7f7 into nytimes:master Sep 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants