Skip to content

Commit

Permalink
make_chm: correctly encode uri
Browse files Browse the repository at this point in the history
  • Loading branch information
myfreeer committed Apr 15, 2021
1 parent 8c1f25a commit 2abd81d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion make_chm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@
$time = $time_end - $time_start;
echo( "\nbuild time: ". $time." seconds.\n");

// https://stackoverflow.com/a/6059053
function encodeURI($url) {
// http://php.net/manual/en/function.rawurlencode.php
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI
$unescaped = array(
'%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!', '%7E'=>'~',
'%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')'
);
$reserved = array(
'%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':',
'%40'=>'@','%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$'
);
$score = array(
'%23'=>'#'
);
return strtr(rawurlencode($url), array_merge($reserved,$unescaped,$score));

}

function fixedEncodeURI($url) {
return strtr(encodeURI($url),array('%5B'=>'[', '%5D'=>']'));
}

function buildChm( $cpp = true )
{
$scriptDir = dirname( __FILE__ );
Expand Down Expand Up @@ -161,7 +184,7 @@ function buildChm( $cpp = true )
$new_value = str_replace( " " , "_", $new_value);
if (! strstr($new_value, "http")) {
// escape relative %
$new_value = str_replace( "%" , "_", urlencode($new_value));
$new_value = str_replace( "%" , "_", fixedEncodeURI($new_value));
}

if ($hash) { // fix hashes
Expand Down

0 comments on commit 2abd81d

Please sign in to comment.