Created
December 13, 2011 17:43
-
-
Save zeisss/1473086 to your computer and use it in GitHub Desktop.
Testcase with buggy highlight_code function from CodeIgniter 2.1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Code Highlighter | |
* | |
* Colorizes code strings | |
* | |
* @access public | |
* @param string the text string | |
* @return string | |
*/ | |
if ( ! function_exists('highlight_code')) | |
{ | |
function highlight_code($str) | |
{ | |
// The highlight string function encodes and highlights | |
// brackets so we need them to start raw | |
$str = str_replace(array('<', '>'), array('<', '>'), $str); | |
// Replace any existing PHP tags to temporary markers so they don't accidentally | |
// break the string out of PHP, and thus, thwart the highlighting. | |
$str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'), | |
array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); | |
// The highlight_string function requires that the text be surrounded | |
// by PHP tags, which we will remove later | |
$str = '<?php '.$str.' ?>'; // <? | |
// All the magic happens here, baby! | |
$str = highlight_string($str, TRUE); | |
// Prior to PHP 5, the highligh function used icky <font> tags | |
// so we'll replace them with <span> tags. | |
if (abs(PHP_VERSION) < 5) | |
{ | |
$str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str); | |
$str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); | |
} | |
// Remove our artificially added PHP, and the syntax highlighting that came with it | |
$str = preg_replace('/<span style="color: #([A-Z0-9]+)"><\?php( | )/i', '<span style="color: #$1">', $str); | |
$str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str); | |
$str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/span>/i', '', $str); | |
// Replace our markers back to PHP tags. | |
$str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), | |
array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); | |
return $str; | |
} | |
} | |
$HTML = <<<EOF | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
function filterSpellIdListe(playersSpellList, spellIDList) { | |
if ( gBlacklist ) { | |
// Filter certain IDs completly | |
spellIDList = jQuery.grep(spellIDList, function(spell, _index) { | |
return spell && jQuery.inArray(spell.id, gBlacklist) == -1; | |
}); | |
} | |
// Filter out the spells from list spellIDList which the player does not have | |
return jQuery.grep(spellIDList, function(spell, _index) { | |
return spell && jQuery.inArray(spell.id, playersSpellList) == -1; | |
}); | |
} | |
function ahspy_itemurl(region, realm, faction, itemId) { | |
return "http://www.ahspy.com/" + region.substr(0,2) + "/" + realm + "/item/" + itemId + "/#" + faction; | |
} | |
function wowhead_spellicon(spell) { | |
if (spell.icon) { | |
return "http://static.wowhead.com/images/wow/icons/large/" + spell.icon + ".jpg"; | |
} | |
return ""; | |
} | |
function wowhead_spellurl(spellId) { | |
return "http://de.wowhead.com/spell=" + spellId; | |
} | |
function useDecorators(spellId, callback) { | |
jQuery.each(gDecoratorAndFilters, function(decorator_index, decorator) { | |
if (!decorator.decorator_text) { | |
return; | |
} | |
if (jQuery.inArray(spellId, decorator.ids) >= 0) { | |
callback(decorator); | |
} | |
}); | |
} | |
jQuery.fn.pet_lister = function(playerSpellList, character, spellIdList) { | |
return this.each(function() { | |
var element = $(this); | |
var spellText; | |
if ($("input[name='typ']:checked").val() == "companions") { | |
spellText = "Haustiere"; | |
} else { | |
spellText = "Reittiere"; | |
} | |
var missingSpells = filterSpellIdListe(playerSpellList, spellIdList); | |
// Process all filters | |
jQuery.each(gDecoratorAndFilters, function(index, value) { | |
if (!value.filter_element_id) | |
return; | |
// Check if the filter is 'checked' | |
if (!$(value.filter_element_id).prop("checked")) { | |
// Filter all ids from that list | |
missingSpells = jQuery.grep(missingSpells, function(spell, index) { | |
return jQuery.inArray(spell.id, value.ids) == -1; | |
}); | |
} | |
}); | |
// Process Faction Filters | |
var charFaction = $.battlenet({'action':'get-faction-by-race', 'race':character.race}); | |
var factionSpellIds = (charFaction == "ALLIANCE" ? gRaceAllianceIds : gRaceHordeIds); | |
var otherFactionSpellIds = (charFaction == "HORDE" ? gRaceAllianceIds : gRaceHordeIds); | |
if (!$("#filter_ownfactionspells").prop("checked")) { | |
missingSpells = jQuery.grep(missingSpells, function(spell, index) { | |
return jQuery.inArray(spell.id, factionSpellIds.ids) == -1; | |
}); | |
} | |
if (!$("#filter_otherfactionspells").prop("checked")) { | |
missingSpells = jQuery.grep(missingSpells, function(spell, index) { | |
return jQuery.inArray(spell.id, otherFactionSpellIds.ids) == -1; | |
}); | |
} | |
missingSpells.reverse(); | |
// Prepare output list | |
var table = $("<table></table>"); | |
if ( missingSpells.length == 0 ) { | |
table.append("<tr><td>Du hast alles!</td></tr>"); | |
} else { | |
var currentTr = undefined; | |
var tdCounter = 0; | |
jQuery.each(missingSpells, function(index, value) { | |
var id = value.id; | |
var name = value.name_dede; | |
var spellUrl = wowhead_spellurl(id); | |
if (currentTr == undefined) { | |
currentTr = $("<tr></tr>").appendTo(table); | |
} | |
var td = $("<td></td>"); | |
currentTr.append(td); | |
var container = $("<div class='item'></div>").appendTo(td); | |
jQuery.each(gDecoratorAndFilters, function(_i, decorator) { | |
if ( decorator.css_class && | |
jQuery.inArray(id, decorator.ids) > -1) { | |
td.addClass(decorator.css_class); | |
} | |
}); | |
container.click(function() { | |
popup_show(character, missingSpells, value); | |
return false; | |
}); | |
var spellIconUrl = wowhead_spellicon(value); | |
if (spellIconUrl) { | |
var img = $("<img />"); | |
img.attr("border", "0"); | |
img.attr("src", spellIconUrl); | |
// container.append($("<a></a>").append(img).attr("href", spellUrl)).append("<br />"); | |
container.append(img).append("<br />"); | |
} | |
// container.append($("<a></a>").attr("href", spellUrl).text(name)).append("<br />"); | |
container.append($("<u></u>").append(name)).append("<br />"); | |
useDecorators(id, function(decorator) { | |
container.append($("<span>" + decorator.decorator_text + "</span><br />")); | |
}); | |
// Close the row after 4 spells | |
tdCounter++; | |
if (tdCounter == 4) { | |
tdCounter = 0; | |
currentTr = undefined; | |
} | |
}); | |
} | |
element.empty(); | |
// resultList.append("You have " + playerSpellList.length + " " + spellText) | |
element.append($("<h2>Du hast " + playerSpellList.length + " " + spellText + " - Dir fehlen "+ missingSpells.length + " " + spellText + ":</h2>")); | |
element.append(table); // Pet Result List | |
}); | |
}; | |
$(document).ready(function(){ | |
// Load cookie data | |
$("#region").val($.cookie('pet_lister_region')); | |
$("#charname").val($.cookie('pet_lister_char')); | |
// Fetch initial realm list | |
$("#region").change(function() { | |
var sRegion = $(this).val(); | |
$("#realm").battlenet({ | |
action: 'fill-with-realms', | |
region: sRegion, | |
selected: | |
$.cookie('pet_lister_realm') | |
}); | |
}).change(); | |
// On Button Click | |
var searchFunction = function() { | |
var sRegion = $("#region").val(); | |
var sRealm = $("#realm").val(); | |
var sChar = $("#charname").val(); | |
var filterType = $("input[name='typ']:checked").val(); | |
// Store values in cookie for page reload | |
$.cookie('pet_lister_region', sRegion); | |
$.cookie('pet_lister_realm', sRealm); | |
$.cookie('pet_lister_char', sChar); | |
// Log the character into our internal database. No data except the region/realm/charcter is logged | |
jQuery.post( | |
window.location.origin != "http://ninjalooter.de" ? 'http://ninjalooter.de/WoWPetLister/api/log_request.php' : './api/log_request.php', | |
{ | |
region: sRegion, | |
realm: sRealm, | |
character: sChar | |
} | |
); | |
// Request the character data and parse the id list afterwards | |
jQuery.battlenet({ | |
action: 'load-character-' + filterType, | |
server: sRegion, | |
realm: sRealm, | |
charname: sChar, | |
handler: function(character) { | |
var result = $("#result_list"); | |
if (filterType == "companions") { | |
result.pet_lister(character.companions, character, gPetSpells); | |
} else { | |
result.pet_lister(character.mounts, character, gMountSpells); | |
} | |
if ( window.$WowheadPower && $WowheadPower.init ) { | |
$WowheadPower.init(); | |
} | |
} | |
}); | |
}; | |
$("#btn_scan").click(searchFunction); | |
$("#charname").keypress(function(event) { | |
if (event.which == 13 ) { | |
searchFunction(); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="page"> | |
<div id="header"> | |
<img id="mauer" src="http://ninjalooter.de/blog/wp-content/uploads/2010/08/Ninjalooter_Header_Mauer1.jpg" width="960" height="120" /> | |
<img id="logo" class="center" title="WoW Pet Lister" src="WPL_Banner.png" alt="" width="600" height="100" /> | |
</div> | |
<div id="nav" class="bar"> | |
Präsentiert von <a href="http://ninjalooter.de" target="_blank">Ninjalooter.de</a> | Version 1.2.2 | |
</div> | |
<div class="content"> | |
<div> | |
<label for="charname">Charakter:</label> | |
<select id="region"> | |
<option value="eu.battle.net">EU</option> | |
<option value="us.battle.net">US</option> | |
<option value="kr.battle.net">KR</option> | |
<option value="tw.battle.net">TW</option> | |
<option value="battlenet.com.cn">CN</option> | |
</select> | |
<select id="realm"> | |
<option value="">Bitte warten</option> | |
</select> | |
<input type="text" id="charname" /> | |
</div> | |
<div style="padding-top:10px"> | |
<table style="border:1px black solid; margin:auto;"> | |
<cols> | |
<col width="150" /> | |
<col width="150" /> | |
<col width="200" /> | |
<col width="150" /> | |
</cols> | |
<tr> | |
<td> | |
Typ: | |
</td> | |
<td colspan="2"> | |
Ursprung: | |
</td> | |
</tr> | |
<tr> | |
<td valign="top" rowspan="3"> | |
<input type="radio" name="typ" id="type_companions" value="companions" checked="checked"> <label for="type_companions">Haustiere</label><br /> | |
<input type="radio" name="typ" id="type_mounts" value="mounts"> <label for="type_mounts">Reittiere</label><br /> | |
</td> | |
<td><input type="checkbox" value="true" id="filter_ownfactionspells" checked="checked" /><label for="filter_ownfactionspells">Eigene Fraktion</label></td> | |
<td><input type="checkbox" value="true" id="filter_lootcards" /><label for="filter_lootcards">Trading Card Game Pets</label></td> | |
<td><input type="checkbox" value="true" id="filter_limited" /><label for="filter_limited">Limited Editions</label></td> | |
</tr> | |
<tr> | |
<td><input type="checkbox" value="true" id="filter_otherfactionspells" /><label for="filter_otherfactionspells">Gegn. Fraktion</label></td> | |
<td><input type="checkbox" value="true" id="filter_blizzcoll" /><label for="filter_blizzcoll">Blizzard Collectables</label></td> | |
<td><input type="checkbox" value="true" id="filter_blizzshop" /><label for="filter_blizzshop">Blizzard Shop</label></td> | |
</tr> | |
<tr> | |
<td><input type="checkbox" value="true" id="filter_classmounts" /><label for="filter_classmounts">Klassen Mounts</label></td> | |
</tr> | |
</table> | |
</div> | |
<div id="buttons"> | |
<button id="btn_scan"><img alt="Scannen." title="Scannen!" style="padding: 0pt 0px 0px 0pt;" src="scan_button4.png"/></button> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> | |
EOF; | |
echo '>' . highlight_code($HTML) . '<'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See bcit-ci/CodeIgniter#778 for the issue.