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

Unrecognized expression because of hashchange trigger #207

Open
fstani opened this issue Sep 5, 2018 · 2 comments
Open

Unrecognized expression because of hashchange trigger #207

fstani opened this issue Sep 5, 2018 · 2 comments

Comments

@fstani
Copy link

fstani commented Sep 5, 2018

Uncaught Error: Syntax error, unrecognized expression: #page=1
    at Function.ot.error (jquery.min.js:4)
    at gt (jquery.min.js:4)
    at kt (jquery.min.js:4)
    at Function.ot [as find] (jquery.min.js:4)
    at init.find (jquery.min.js:5)
    at new init (jquery.min.js:4)
    at x (jquery.min.js:4)
    at iziModal.min.js:formatted:607
    at dispatch (jquery.min.js:5)
    at y.handle (jquery.min.js:5)

When manually changing the hash, an error is thrown on this code:

o.off("hashchange." + a).on("hashchange." + a, function(e) {
        var i = document.location.hash
          , n = t(i).data();
        if ("" !== i)
            try {
                "undefined" != typeof n && "opening" !== t(i).iziModal("getState") && setTimeout(function() {
                    t(i).iziModal("open")
                }, 200)
            } catch (o) {}
        else
            window.$iziModal.history && t.each(t("." + a), function(e, i) {
                if (void 0 !== t(i).data().iziModal) {
                    var n = t(i).iziModal("getState");
                    "opened" != n && "opening" != n || t(i).iziModal("close")
                }
            })
    }),

Perhaps a try catch on the t(i).data() would be enough, or a checking it instead of assuming what is in the hash has anything to do with iziModal.

@fstani
Copy link
Author

fstani commented Sep 5, 2018

This mitigates the issue, but it would be nice to review the underlying cause.

o.off("hashchange." + a).on("hashchange." + a, function(e) {
        var i = document.location.hash, n;
        try {
            n = t(i).data();
        } catch (e) {
        }
        if ("" !== i)
            try {
                "undefined" != typeof n && "opening" !== t(i).iziModal("getState") && setTimeout(function() {
                    t(i).iziModal("open")
                }, 200)
            } catch (o) {}
        else
            window.$iziModal.history && t.each(t("." + a), function(e, i) {
                if (void 0 !== t(i).data().iziModal) {
                    var n = t(i).iziModal("getState");
                    "opened" != n && "opening" != n || t(i).iziModal("close")
                }
            })
    }),

@gabipetrovay
Copy link

👍

I encountered this issue using another jQuery plugin (fullpage.js) which automatically changes the page fragments (hashes) and the contain slash (e.g. #section/slide).

The syntax of the hash can be more complex than a string. See the example on Wikipedia.

iziModal tries to pass the hash as it is directly to jQuery without any validation:

// ...
var data = $(modalHash).data();
// ...

Solutions:

  1. Validate the hash (not the most trivial solution). A hint on StackOverflow.
  2. Have an iziModal initialisation option to completely disable.
  3. Allow the user to control the hashchange.iziModal behaviour via the API.

Solution 2 and 3 should be available for the user.

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

No branches or pull requests

2 participants