<commit_before>
// global overpass object

var overpass = new(function() {
  // == private members ==
  // == public members ==
  this.handlers = {};

  // == private methods ==
  var fire = function() {
    var args = fire.arguments;
    var name = args[0];
    if (typeof overpass.handlers[name] != "function")
      return undefined;
    var handler_args = [];
    for (var i=1; i<args.length; i++) 
      handler_args.push(args[i]);
    return overpass.handlers[name].apply({},handler_args);
  }

  // == public methods ==

  // updates the map
  this.run_query = function (query, query_lang) {
    // 1. get overpass json data
    fire("onProgress", "building query");
    if (query_lang == "xml") {
      // beautify not well formed xml queries (workaround for non matching error lines)
      if (!query.match(/^<\?xml/)) {
        if (!query.match(/<osm-script/))
          query = '<osm-script>'+query+'</osm-script>';
        query = '<?xml version="1.0" encoding="UTF-8"?>'+query;
      }
    }
    fire("onProgress", "calling Overpass API interpreter", function() {
      // kill the query on abort
      overpass.ajax_request.abort();
      // try to abort queries via kill_my_queries
      $.get(settings.server+"kill_my_queries");
    });
    var request_headers = {};
    var additional_get_data = "";
    if (settings.force_simple_cors_request) {
      additional_get_data = "?X-Requested-With="+configs.appname;
    } else {
      request_headers["X-Requested-With"] = configs.appname;
    }
    overpass.ajax_request = $.ajax(settings.server+"interpreter"+additional_get_data, {
      type: 'POST',
      data: {data:query},
      headers: request_headers,
      success: function(data, textStatus, jqXHR) {
        var data_amount = jqXHR.responseText.length;
        var data_txt;
        // round amount of data
        var scale = Math.floor(Math.log(data_amount)/Math.log(10));
        data_amount = Math.round(data_amount / Math.pow(10,scale)) * Math.pow(10,scale);
        if (data_amount < 1000)
          data_txt = data_amount + " bytes";
        else if (data_amount < 1000000)
          data_txt = data_amount / 1000 + " kB";
        else
          data_txt = data_amount / 1000000 + " MB";
        fire("onProgress", "recieved about "+data_txt+" of data");
        fire("onDataRecieved", data_amount, data_txt, 
        function() { // abort callback
          fire("onAbort");
          return;
        }, function() { // continue callback
        // different cases of loaded data: json data, xml data or error message?
        var data_mode = null;
        var geojson;
        var stats = {};
        fire("onProgress", "parsing data");
setTimeout(function() {
        // hacky firefox hack :( (it is not properly detecting json from the content-type header)
        if (typeof data == "string" && data[0] == "{") { // if the data is a string, but looks more like a json object
          try {
            data = $.parseJSON(data);
          } catch (e) {}
        }
        if ((typeof data == "string") ||
            (typeof data == "object" && jqXHR.responseXML && $("remark",data).length > 0) ||
            (typeof data == "object" && data.remark && data.remark.length > 0)
           ) { // maybe an error message
          data_mode = "unknown";
          var is_error = false;
          is_error = is_error || (typeof data == "string" && // html coded error messages
            data.indexOf("Error") != -1 && 
            data.indexOf("<script") == -1 && // detect output="custom" content
            data.indexOf("<h2>Public Transport Stops</h2>") == -1); // detect output="popup" content
          is_error = is_error || (typeof data == "object" &&
            jqXHR.responseXML &&
            $("remark",data).length > 0);
          is_error = is_error || (typeof data == "object" &&
            data.remark &&
            data.remark.length > 0);<commit_msg>hotfix for firefox not parsing application/osm3s+xml data from Overpass i assume this was introduced with the upgrade to jquery2 - will have a deeper look<commit_after>
// global overpass object

var overpass = new(function() {
  // == private members ==
  // == public members ==
  this.handlers = {};

  // == private methods ==
  var fire = function() {
    var args = fire.arguments;
    var name = args[0];
    if (typeof overpass.handlers[name] != "function")
      return undefined;
    var handler_args = [];
    for (var i=1; i<args.length; i++) 
      handler_args.push(args[i]);
    return overpass.handlers[name].apply({},handler_args);
  }

  // == public methods ==

  // updates the map
  this.run_query = function (query, query_lang) {
    // 1. get overpass json data
    fire("onProgress", "building query");
    if (query_lang == "xml") {
      // beautify not well formed xml queries (workaround for non matching error lines)
      if (!query.match(/^<\?xml/)) {
        if (!query.match(/<osm-script/))
          query = '<osm-script>'+query+'</osm-script>';
        query = '<?xml version="1.0" encoding="UTF-8"?>'+query;
      }
    }
    fire("onProgress", "calling Overpass API interpreter", function() {
      // kill the query on abort
      overpass.ajax_request.abort();
      // try to abort queries via kill_my_queries
      $.get(settings.server+"kill_my_queries");
    });
    var request_headers = {};
    var additional_get_data = "";
    if (settings.force_simple_cors_request) {
      additional_get_data = "?X-Requested-With="+configs.appname;
    } else {
      request_headers["X-Requested-With"] = configs.appname;
    }
    overpass.ajax_request = $.ajax(settings.server+"interpreter"+additional_get_data, {
      type: 'POST',
      data: {data:query},
      headers: request_headers,
      success: function(data, textStatus, jqXHR) {
        var data_amount = jqXHR.responseText.length;
        var data_txt;
        // round amount of data
        var scale = Math.floor(Math.log(data_amount)/Math.log(10));
        data_amount = Math.round(data_amount / Math.pow(10,scale)) * Math.pow(10,scale);
        if (data_amount < 1000)
          data_txt = data_amount + " bytes";
        else if (data_amount < 1000000)
          data_txt = data_amount / 1000 + " kB";
        else
          data_txt = data_amount / 1000000 + " MB";
        fire("onProgress", "recieved about "+data_txt+" of data");
        fire("onDataRecieved", data_amount, data_txt, 
        function() { // abort callback
          fire("onAbort");
          return;
        }, function() { // continue callback
        // different cases of loaded data: json data, xml data or error message?
        var data_mode = null;
        var geojson;
        var stats = {};
        fire("onProgress", "parsing data");
setTimeout(function() {
        // hacky firefox hack :( (it is not properly detecting json from the content-type header)
        if (typeof data == "string" && data[0] == "{") { // if the data is a string, but looks more like a json object
          try {
            data = $.parseJSON(data);
          } catch (e) {}
        }
        if (typeof data == "string" && data.substr(0,5) == "<?xml") {
          try {
            jqXHR.responseXML = data;
            data = $.parseXML(data);
          } catch (e) {
            delete jqXHR.responseXML;
          }
        }
        if ((typeof data == "string") ||
            (typeof data == "object" && jqXHR.responseXML && $("remark",data).length > 0) ||
            (typeof data == "object" && data.remark && data.remark.length > 0)
           ) { // maybe an error message
          data_mode = "unknown";
          var is_error = false;
          is_error = is_error || (typeof data == "string" && // html coded error messages
            data.indexOf("Error") != -1 && 
            data.indexOf("<script") == -1 && // detect output="custom" content
            data.indexOf("<h2>Public Transport Stops</h2>") == -1); // detect output="popup" content
          is_error = is_error || (typeof data == "object" &&
            jqXHR.responseXML &&
            $("remark",data).length > 0);
          is_error = is_error || (typeof data == "object" &&
            data.remark &&
            data.remark.length > 0);
{'fraction_non_alphanumeric': 0.14634146341463414, 'fraction_numerical': 0.01121951219512195, 'mean_word_length': 2.302859444220701, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 2, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5781224', 'n_tokens_mistral': 2492, 'n_tokens_neox': 2409, 'n_words': 633}