<commit_before>/**
 * @author:		<NAME>
 * @copyright:	http://www.divio.ch under the BSD Licence
 * @requires:	Classy, jQuery
 *
 * assign Class and CMS namespace */
 var CMS = CMS || {};
     CMS.Class = CMS.Class || Class.$noConflict();
     CMS.API = CMS.API || {};

(function ($) {
/*##################################################|*/
/* #CMS.BASE# */
jQuery(document).ready(function ($) {
	/**
	 * Security
	 * @version: 0.1.1
	 * @description: Adds security layer to CMS namespace
	 * @public_methods:
	 *	- CMS.Security.csrf();
	 */
	CMS.API.Security = {
	
		csrf: function () {
			$.ajaxSetup({
				beforeSend: function (xhr, settings) {
					// get cookies without jquery.cookie.js
					function getCookie(name) {
						var cookieValue = null;
						if(document.cookie && (document.cookie != '')) {
							var cookies = document.cookie.split(';');
							for (var i = 0; i < cookies.length; i++) {
								var cookie = $.trim(cookies[i]);
								// Does this cookie string begin with the name we want?
								if (cookie.substring(0, name.length + 1) == (name + '=')) {
									cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
									break;
								}
							}
						}
						return cookieValue;
					}
					// do some url checks
					var base_doc_url = document.URL.match(/^http[s]{0,1}:\/\/[^\/]+\//)[0];
					var base_settings_url = settings.url.match(/^http[s]{0,1}:\/\/[^\/]+\//);
					if(base_settings_url != null) {
						base_settings_url = base_settings_url[0];
					}
					if(!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url)) || base_doc_url == base_settings_url) {
						// Only send the token to relative URLs i.e. locally.
						xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
					}
				}
			});
			
			return 'ready';
		}
	
	};
	
	/**
	 * Helpers
	 * @version: 0.1.1
	 * @description: Adds helper methods to be invoked
	 * @public_methods:
	 *	- CMS.Helpers.reloadBrowser();
	 *	- CMS.Helpers.getUrl(str);
	 *	- CMS.Helpers.setUrl(getUrlObj, addParam, removeParam);
	 */
	CMS.API.Helpers = {
	
		reloadBrowser: function () {
			window.location.reload();
		},

		getUrl: function(str) {
			var	o = {
				'strictMode': false,
				'key': ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
				'q': { 'name': 'queryKey', 'parser': /(?:^|&)([^&=]*)=?([^&]*)/g },
				'parser': {
					'strict': /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
					'loose':  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
				}
			};
			
			var m = o.parser[o.strictMode ? 'strict' : 'loose'].exec(str), uri = {}, i = 14;

			while(i--) uri[o.key[i]] = m[i] || '';

			uri[o.q.name] = {};
			uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
				if($1) { uri[o.q.name][$1] = $2; }
			});

			return uri;
		},

		setUrl: function (getUrlObj, addParam, removeParam) {
			var query = getUrlObj.queryKey;
			var serialized = '';
			var index = 0;

			// we could loop the query and replace the param at the right place
			// but instead of replacing it just append it to the end of the query so its more visible
			delete query[removeParam];
				   query[addParam.split('=')[0]] = addParam.split('=')[1];

			$.each(query, function (key, value) {
				// add &
				if(index != 0) serialized += '&';
				// if a value is given attach it
				serialized += (value) ? (key + '=' + value) : (key);
				index++;
			});

			// check if we should add the questionmark
			var addition = (serialized === '') ? '' : '?';
			var anchor = (getUrlObj.anchor) ? '#' + getUrlObj.anchor : '';

			// if no params are given just return the normal url
			if(options && (options.removeParam || options.addParam)) {
				uri = getUrlObj.protocol + '://' + getUrlObj.authority + getUrlObj.directory + getUrlObj.file + addition + serialized + anchor;
			} else {
				uri = getUrlObj.source;
			}

			return uri;
		}
	
	};

});

})(jQuery);<commit_msg>copy cms.base from qunit testing<commit_after>/**
 * @author:		<NAME>
 * @copyright:	http://www.divio.ch under the BSD Licence
 * @requires:	Classy, jQuery
 *
 * assign Class and CMS namespace */
 var CMS = CMS || {};
     CMS.Class = CMS.Class || Class.$noConflict();

(function ($) {
/*##################################################|*/
/* #CMS.BASE# */
jQuery(document).ready(function ($) {
	/**
	 * Security
	 * @version: 1.0.0
	 * @description: Adds security layer to CMS namespace
	 * @public_methods:
	 *	- CMS.Security.csrf();
	 */
	CMS.Security = {
	
		csrf: function () {
			$.ajaxSetup({
				beforeSend: function (xhr, settings) {
					// get cookies without jquery.cookie.js
					function getCookie(name) {
						var cookieValue = null;
						if(document.cookie && (document.cookie != '')) {
							var cookies = document.cookie.split(';');
							for (var i = 0; i < cookies.length; i++) {
								var cookie = $.trim(cookies[i]);
								// Does this cookie string begin with the name we want?
								if (cookie.substring(0, name.length + 1) == (name + '=')) {
									cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
									break;
								}
							}
						}
						return cookieValue;
					}
					// do some url checks
					var base_doc_url = document.URL.match(/^http[s]{0,1}:\/\/[^\/]+\//)[0];
					var base_settings_url = settings.url.match(/^http[s]{0,1}:\/\/[^\/]+\//);
					if(base_settings_url != null) {
						base_settings_url = base_settings_url[0];
					}
					if(!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url)) || base_doc_url == base_settings_url) {
						// Only send the token to relative URLs i.e. locally.
						xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
					}
				}
			});
			return 'ready';
		}
	
	};
	
	/**
	 * Helpers
	 * @version: 0.1.1
	 * @description: Adds helper methods to be invoked
	 * @public_methods:
	 *	- CMS.Helpers.reloadBrowser();
	 *	- CMS.Helpers.getUrl(urlString);
	 *	- CMS.Helpers.setUrl(urlString, options);
	 */
	CMS.Helpers = {
	
		reloadBrowser: function () {
			window.location.reload();
		},

		getUrl: function(str) {
			var	o = {
				'strictMode': false,
				'key': ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
				'q': { 'name': 'queryKey', 'parser': /(?:^|&)([^&=]*)=?([^&]*)/g },
				'parser': {
					'strict': /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
					'loose':  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
				}
			};
			
			var m = o.parser[o.strictMode ? 'strict' : 'loose'].exec(str), uri = {}, i = 14;

			while(i--) uri[o.key[i]] = m[i] || '';

			uri[o.q.name] = {};
			uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
				if($1) { uri[o.q.name][$1] = $2; }
			});

			return uri;
		},

		setUrl: function (str, options) {
			var uri = str;

			// now we neet to get the partials of the element
			var getUrlObj = this.getUrl(uri);
			var query = getUrlObj.queryKey;
			var serialized = '';
			var index = 0;

			// we could loop the query and replace the param at the right place
			// but instead of replacing it just append it to the end of the query so its more visible
			if(options && options.removeParam) delete query[options.removeParam];
			if(options && options.addParam) query[options.addParam.split('=')[0]] = options.addParam.split('=')[1];

			$.each(query, function (key, value) {
				// add &
				if(index != 0) serialized += '&';
				// if a value is given attach it
				serialized += (value) ? (key + '=' + value) : (key);
				index++;
			});

			// check if we should add the questionmark
			var addition = (serialized === '') ? '' : '?';
			var anchor = (getUrlObj.anchor) ? '#' + getUrlObj.anchor : '';

			uri = getUrlObj.protocol + '://' + getUrlObj.authority + getUrlObj.directory + getUrlObj.file + addition + serialized + anchor;

			return uri;
		}
	
	};

});

})(jQuery);
{'fraction_non_alphanumeric': 0.2678422494936256, 'fraction_numerical': 0.00714881448826403, 'mean_word_length': 2.920597851471275, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4106450', 'n_tokens_mistral': 3671, 'n_tokens_neox': 2985, 'n_words': 591}