<commit_before>$(function() {
  $('#persona-form').submit(function(e) {
    if (!$('#persona-assertion').val()) {
      e.preventDefault();
      navigator.id.get(function(assertion) {
        if (assertion) {
          $('#persona-assertion').val(assertion);
          $('#persona-form').submit();
        } else {
          location.reload();
        }
      });
    }
  });

  $('#ldap-modal').on('shown.bs.modal', function() {
    $('#ldap-modal input[name="username"]').focus();
  });

  $('#manual-form').submit(function(e) {
    e.preventDefault();
    showCredentials({
      clientId: $('#manual-modal input[name="clientId"]').val().trim(),
      accessToken: $('#manual-modal input[name="accessToken"]').val().trim(),
      certificate: $('#manual-modal textarea[name="certificate"]').val().trim(),
    });
    $('#manual-modal').modal('hide');
  });

  $('#manual-modal').on('shown.bs.modal', function() {
    $('#manual-modal input[name="clientId"]').focus();
  });
});


jQuery.extend({
  getQueryString: function() {
    var parts = (document.location.search || '')
                .replace(/(^\?)/,'').split(/=|&/g);
    var result = {};
    for(var i = 0; i < parts.length - 1; i += 2) {
      result[decodeURIComponent(parts[i])] = decodeURIComponent(parts[i + 1]);
    }
    return result;
  }
});

// Okay, this isn't pretty... But we have to store the stuff we got from the
// query string in local storage, as we grant carry the query string with us
// through all the login steps (particular SSO)
// Due to size we don't even try to store in a cookie, which would have the same
// result, basically that authenticating in two windows of the same browser
// in parallel would cause issues... But why would people do that???
var query = $.getQueryString();
if (typeof(query.target) === 'string' && /^http/.test(query.target) &&
    typeof(query.description) === 'string') {
  var a = document.createElement('a');
  a.href = query.target;
  if (a.protocol === 'https:' || a.hostname === 'localhost' ||
      a.hostname === 'docs.taskcluster.net') {
    localStorage.setItem('grant-request', JSON.stringify({
      target: query.target,
      description: query.description
    }));
    // Get rid of those ugly query-strings...
    window.location = '/';
  } else {
    console.log("target " + query.target + " isn't valid, http only allowed " +
                "for localhost");
  }
}

// Check if we can naively redirect to a host
function isAllowedHost(host) {
  if (window.allowedHosts.indexOf(host) !== -1) {
    return true;
  }
  try {
    var hosts = JSON.parse(localStorage.getItem('allowed-hosts') || '[]');
    return hosts.indexOf(host) !== -1;
  } catch(err) {
    console.log("Ignore JSON.parse errors... (probably invalid value)");
  }
  return false;
}<commit_msg>Bug 1271982: remove the special case allowing docs access with http<commit_after>$(function() {
  $('#persona-form').submit(function(e) {
    if (!$('#persona-assertion').val()) {
      e.preventDefault();
      navigator.id.get(function(assertion) {
        if (assertion) {
          $('#persona-assertion').val(assertion);
          $('#persona-form').submit();
        } else {
          location.reload();
        }
      });
    }
  });

  $('#ldap-modal').on('shown.bs.modal', function() {
    $('#ldap-modal input[name="username"]').focus();
  });

  $('#manual-form').submit(function(e) {
    e.preventDefault();
    showCredentials({
      clientId: $('#manual-modal input[name="clientId"]').val().trim(),
      accessToken: $('#manual-modal input[name="accessToken"]').val().trim(),
      certificate: $('#manual-modal textarea[name="certificate"]').val().trim(),
    });
    $('#manual-modal').modal('hide');
  });

  $('#manual-modal').on('shown.bs.modal', function() {
    $('#manual-modal input[name="clientId"]').focus();
  });
});


jQuery.extend({
  getQueryString: function() {
    var parts = (document.location.search || '')
                .replace(/(^\?)/,'').split(/=|&/g);
    var result = {};
    for(var i = 0; i < parts.length - 1; i += 2) {
      result[decodeURIComponent(parts[i])] = decodeURIComponent(parts[i + 1]);
    }
    return result;
  }
});

// Okay, this isn't pretty... But we have to store the stuff we got from the
// query string in local storage, as we grant carry the query string with us
// through all the login steps (particular SSO)
// Due to size we don't even try to store in a cookie, which would have the same
// result, basically that authenticating in two windows of the same browser
// in parallel would cause issues... But why would people do that???
var query = $.getQueryString();
if (typeof(query.target) === 'string' && /^http/.test(query.target) &&
    typeof(query.description) === 'string') {
  var a = document.createElement('a');
  a.href = query.target;
  if (a.protocol === 'https:' || a.hostname === 'localhost') {
    localStorage.setItem('grant-request', JSON.stringify({
      target: query.target,
      description: query.description
    }));
    // Get rid of those ugly query-strings...
    window.location = '/';
  } else {
    console.log("target " + query.target + " isn't valid, http only allowed " +
                "for localhost");
  }
}

// Check if we can naively redirect to a host
function isAllowedHost(host) {
  if (window.allowedHosts.indexOf(host) !== -1) {
    return true;
  }
  try {
    var hosts = JSON.parse(localStorage.getItem('allowed-hosts') || '[]');
    return hosts.indexOf(host) !== -1;
  } catch(err) {
    console.log("Ignore JSON.parse errors... (probably invalid value)");
  }
  return false;
}
{'fraction_non_alphanumeric': 0.19250669045495095, 'fraction_numerical': 0.003389830508474576, 'mean_word_length': 3.0800582241630274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3659896', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1705, 'n_words': 420}