Demo entry 3300415

javascript file

   

Submitted by anonymous on Dec 10, 2015 at 10:53
Language: JavaScript. Code size: 2.1 kB.

var uTp = require("./urlToPattern.js");

//crearea unor functii proprii
function removeUserSpecific(pattern){
	var userSpecificKeywordsList = ["^session$","^s?id$","^e?mail$"];
	var queryPart = pattern.query;

	//for each component in query
	for(var component in queryPart){

		//test if the component is a string
		if(typeof(queryPart[component]) == "string"){
			var element = queryPart[component];
			var index = parseInt(component);

			//test if the component matches any keyword
			for(var keyword in userSpecificKeywordsList){
				if(element.match(new RegExp(userSpecificKeywordsList[keyword],"gi"))){

					//test if the component is followed by at least two elements
					if(component<queryPart.length-2){

						//test if the component is followed by a keyval object
						if(queryPart[index+1].type == "keyValSeparator"){

							//test if the next component is a string AND is followed by a paramsSeparator obj
								//OR the query ends with that string
							if(typeof(queryPart[index+2]) == "string" &&
										(index+3 == queryPart.length || 
											(index+3 < queryPart.length && queryPart[index+3].type == "paramsSeparator"))){

								queryPart[index+2] = {type:"userSpecific"};
								break;
							}
						}
					}
				}
			}
		}
	}
	pattern.query = queryPart;
}

var urlString = 'http://www.google.com/a.php?pay=1&paypal=2';

//crearea pattern-ului
var myPattern = uTp.urlToPattern(urlString, [
											uTp .keepKeywords(["paypal","google"]), 
											uTp .removeBase16string(2,40),
											removeUserSpecific
											]);

//generarea expresiei regulate corespunzatoare url-ului
//crearea functiilor de transformare a obiectelor in regex
function userSpecificToRegex(obj){
	switch (obj.type){
		case "userSpecific":
			//any character except '&' and '='
			return "((?!&|=).)+";
		default:
			return null;
	}
}

var regex = uTp.patternToRegex(myPattern,[
									  	 base16StringToRegex,
									 	 keepKeywordsToRegex,
									 	 userSpecificToRegex
									 	 ]);

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).