<commit_before><script src="../bower_components/page/page.js"></script>
<script>
  window.addEventListener('WebComponentsReady', function() {

    /**
     * Middleware for authentication check
     */
    function authenticate(ctx, next) {
      qstr = _parseQuery(ctx.querystring);

      // Check if we find credentials in parameters (used for omniauth)
      // if true : store credentials and remove them from the query string
      if (qstr.auth_token) {
        BnbService.storeCredentials(qstr.auth_token, qstr.uid, qstr.client_id);
        _removeParameters();
      }

      // Check if we find a message in the query string.
      // If true : display it to the user
      if (qstr.message) {
        app.showToast(qstr.message);
      }

      if (ctx.pathname==='/signin' || ctx.pathname==='/signup' || ctx.pathname==='/forgot' || ctx.pathname==='/edit-password') {
        next();
      }
      else if (app.isLogged()) {
        next();
      }
      else {
        page.redirect('/signin');
      }
    }

    function analytics(ctx, next) {
      ga('send', 'pageview', ctx.pathname);
      next();
    }

    function loadPages(ctx, next) {
      app.loadPages();
      next();
    }

    function loadPage(ctx, next) {
      var id = ctx.params.id;
      app.loadPage(id);
      next();
    }

    function loadUser(ctx, next) {
      app.loadUser();
      next();
    }

    function loadMembers(ctx, next) {
      var id = ctx.params.id;
      app.loadMembers(id);
      next();
    }

    // Interceptor for all pages
    page('*', authenticate, analytics, function(ctx, next) {
      next();
    });

    page('/signin', function() {
      app.route = 'signin';
    });

    page('/signup', function() {
      app.route = 'signup';
    });

    page('/forgot', function() {
      app.route = 'forgot';
    });

    page('/edit-password', function() {
      app.route = 'edit-password';
    });

    page('/', loadPages, function() {
      app.route = 'home';
    });

    page('/preferences', loadUser, function() {
      app.route = 'preferences';
    });

    page('/page/:id', loadPage, function() {
      app.route = 'page';
    });

    page('/edit-page/:id', loadPage, function() {
      app.route = 'edit-page';
    });

    page('/edit-members/:id', loadMembers, function() {
      app.route = 'edit-members';
    });

    page('/add-page', function() {
      app.route = 'add-page';
    });

    // 404
    page('*', function() {
      app.showToast('Can\'t find: ' + window.location.href  + '. Redirected you to Home Page');
      page.redirect(app.baseUrl);
    });

    page({
      hashbang: true
    });

    function _parseQuery(qstr) {
      var query = {};
      if (qstr.indexOf('#') >= 0) {
        qstr = qstr.slice(0, qstr.indexOf('#'));
      }
      var a = qstr.split('&');
      for (var i = 0; i < a.length; i++) {
          var b = a[i].split('=');
          query[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
      }
      return query;
    }

    /**
     * Remove all query string from the url (and hash too)
     */
    function _removeParameters() {
      var newLocation = window.location.protocol + '//'+
              window.location.host+
              window.location.pathname;
      window.history.pushState('', document.title, newLocation);
    }
  });
</script><commit_msg>Fix query string parsing where there is a question mark<commit_after><script src="../bower_components/page/page.js"></script>
<script>
  window.addEventListener('WebComponentsReady', function() {

    /**
     * Middleware for authentication check
     */
    function authenticate(ctx, next) {
      qstr = _parseQuery(ctx.querystring);

      // Check if we find credentials in parameters (used for omniauth)
      // if true : store credentials and remove them from the query string
      if (qstr.auth_token) {
        BnbService.storeCredentials(qstr.auth_token, qstr.uid, qstr.client_id);
        _removeParameters();
      }

      // Check if we find a message in the query string.
      // If true : display it to the user
      if (qstr.message) {
        app.showToast(qstr.message);
      }

      if (ctx.pathname==='/signin' || ctx.pathname==='/signup' || ctx.pathname==='/forgot' || ctx.pathname==='/edit-password') {
        next();
      }
      else if (app.isLogged()) {
        next();
      }
      else {
        page.redirect('/signin');
      }
    }

    function analytics(ctx, next) {
      ga('send', 'pageview', ctx.pathname);
      next();
    }

    function loadPages(ctx, next) {
      app.loadPages();
      next();
    }

    function loadPage(ctx, next) {
      var id = ctx.params.id;
      app.loadPage(id);
      next();
    }

    function loadUser(ctx, next) {
      app.loadUser();
      next();
    }

    function loadMembers(ctx, next) {
      var id = ctx.params.id;
      app.loadMembers(id);
      next();
    }

    // Interceptor for all pages
    page('*', authenticate, analytics, function(ctx, next) {
      next();
    });

    page('/signin', function() {
      app.route = 'signin';
    });

    page('/signup', function() {
      app.route = 'signup';
    });

    page('/forgot', function() {
      app.route = 'forgot';
    });

    page('/edit-password', function() {
      app.route = 'edit-password';
    });

    page('/', loadPages, function() {
      app.route = 'home';
    });

    page('/preferences', loadUser, function() {
      app.route = 'preferences';
    });

    page('/page/:id', loadPage, function() {
      app.route = 'page';
    });

    page('/edit-page/:id', loadPage, function() {
      app.route = 'edit-page';
    });

    page('/edit-members/:id', loadMembers, function() {
      app.route = 'edit-members';
    });

    page('/add-page', function() {
      app.route = 'add-page';
    });

    // 404
    page('*', function() {
      app.showToast('Can\'t find: ' + window.location.href  + '. Redirected you to Home Page');
      page.redirect(app.baseUrl);
    });

    page({
      hashbang: true
    });

    function _parseQuery(qstr) {
      var query = {};
      if (qstr.indexOf('#') >= 0) {
        qstr = qstr.slice(0, qstr.indexOf('#'));
      }
      if (qstr.indexOf('?') >= 0) {
        qstr = qstr.slice(0, qstr.indexOf('?'));
      }
      var a = qstr.split('&');
      for (var i = 0; i < a.length; i++) {
          var b = a[i].split('=');
          query[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
      }
      return query;
    }

    /**
     * Remove all query string from the url (and hash too)
     */
    function _removeParameters() {
      var newLocation = window.location.protocol + '//'+
              window.location.host+
              window.location.pathname;
      window.history.pushState('', document.title, newLocation);
    }
  });
</script>
{'fraction_non_alphanumeric': 0.17229779142898932, 'fraction_numerical': 0.0026327336551118913, 'mean_word_length': 2.115261958997722, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1968969', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2141, 'n_words': 462}