Skip to content

Commit 2abd81d

Browse files
committed
make_chm: correctly encode uri
See alse https://stackoverflow.com/a/6059053 Fix #18
1 parent 8c1f25a commit 2abd81d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

make_chm.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@
1313
$time = $time_end - $time_start;
1414
echo( "\nbuild time: ". $time." seconds.\n");
1515

16+
// https://stackoverflow.com/a/6059053
17+
function encodeURI($url) {
18+
// http://php.net/manual/en/function.rawurlencode.php
19+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI
20+
$unescaped = array(
21+
'%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!', '%7E'=>'~',
22+
'%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')'
23+
);
24+
$reserved = array(
25+
'%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':',
26+
'%40'=>'@','%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$'
27+
);
28+
$score = array(
29+
'%23'=>'#'
30+
);
31+
return strtr(rawurlencode($url), array_merge($reserved,$unescaped,$score));
32+
33+
}
34+
35+
function fixedEncodeURI($url) {
36+
return strtr(encodeURI($url),array('%5B'=>'[', '%5D'=>']'));
37+
}
38+
1639
function buildChm( $cpp = true )
1740
{
1841
$scriptDir = dirname( __FILE__ );
@@ -161,7 +184,7 @@ function buildChm( $cpp = true )
161184
$new_value = str_replace( " " , "_", $new_value);
162185
if (! strstr($new_value, "http")) {
163186
// escape relative %
164-
$new_value = str_replace( "%" , "_", urlencode($new_value));
187+
$new_value = str_replace( "%" , "_", fixedEncodeURI($new_value));
165188
}
166189

167190
if ($hash) { // fix hashes

0 commit comments

Comments
 (0)