Different kinds of sanitizers for options
(function ( $ ) { | |
$.fn.copyText = function( options ) { | |
// copy the text from the chosen element. | |
let target = options.textSrcSelector | |
let target0 = options.textSrcSelector0 | |
let target1 = options.textSrcSelector1 | |
let target2 = options.textSrcSelector2 | |
let target3 = options.textSrcSelector3 | |
let target4 = options.textSrcSelector4 | |
let target5 = options.textSrcSelector5 | |
let target6 = options.textSrcSelector6 | |
// the only unsafe option | |
let text = $(options.textSrcSelector).text(); | |
// sanitized variable used directly as the argument to $ | |
if(typeof target0 != "string"){ | |
text = $(target0).text(); | |
} | |
// sanitized variable used to only verify | |
if(typeof target1 != "string"){ | |
text = $(options.textSrcSelector1).text(); | |
} | |
// equality check instead of inequality | |
if(typeof target2 == "string"){ | |
text = $(document).find(options.textSrcSelector2).text(); | |
} | |
else | |
{ | |
text = $(options.textSrcSelector2).text(); | |
} | |
// jquery property undefined check | |
if (typeof target3.jquery !== "undefined") { | |
$(target3).append(x); | |
} | |
// jquery property undefined check | |
if (typeof target4.jquery === "undefined") | |
{ | |
text = $(document).find(target4).text(); | |
} | |
else | |
{ | |
text = $(target4).text(); | |
} | |
// direct jquery property access check | |
if (target5.jquery) { | |
text = $(target5).text(); | |
} | |
// negation of direct jquery property access check | |
if (!target6.jquery) { | |
text = $(document).find(target6).text(); | |
} | |
else{ | |
text = $(target6).text(); | |
} | |
return this.text(text); | |
}; | |
}( jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment