Redirect: URL-encode input term after processing input
In the redirect controller, rather than URL-encoding the entire input term before processing it, only URL-encode (the relevant parts of) it in the URL that the redirect controller generates. This ensures that the original input term can be pattern-matched appropriately. Fixes #90.
This commit is contained in:
parent
23583ef7ab
commit
7d0df67ded
|
@ -10,7 +10,7 @@ class RedirectController {
|
||||||
static public function redirect() {
|
static public function redirect() {
|
||||||
$endpoint = '/';
|
$endpoint = '/';
|
||||||
if (isset($_GET['type'], $_GET['term'])) {
|
if (isset($_GET['type'], $_GET['term'])) {
|
||||||
$term = urlencode(trim($_GET['term']));
|
$term = trim($_GET['term']);
|
||||||
switch ($_GET['type']) {
|
switch ($_GET['type']) {
|
||||||
case 'url':
|
case 'url':
|
||||||
$endpoint = self::to_endpoint($term);
|
$endpoint = self::to_endpoint($term);
|
||||||
|
@ -24,22 +24,22 @@ class RedirectController {
|
||||||
if ($term[0] === '@') {
|
if ($term[0] === '@') {
|
||||||
$term = substr($term, 1);
|
$term = substr($term, 1);
|
||||||
}
|
}
|
||||||
$endpoint = '/@' . $term;
|
$endpoint = '/@' . urlencode($term);
|
||||||
break;
|
break;
|
||||||
case 'tag':
|
case 'tag':
|
||||||
// Remove # if sent
|
// Remove # if sent
|
||||||
if ($term[0] === '#') {
|
if ($term[0] === '#') {
|
||||||
$term = substr($term, 1);
|
$term = substr($term, 1);
|
||||||
}
|
}
|
||||||
$endpoint = '/tag/' . $term;
|
$endpoint = '/tag/' . urlencode($term);
|
||||||
break;
|
break;
|
||||||
case 'music':
|
case 'music':
|
||||||
$endpoint = '/music/' . $term;
|
$endpoint = '/music/' . urlencode($term);
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
// The @username part is not used, but
|
// The @username part is not used, but
|
||||||
// it is the schema that TikTok follows
|
// it is the schema that TikTok follows
|
||||||
$endpoint = '/@placeholder/video/' . $term;
|
$endpoint = '/@placeholder/video/' . urlencode($term);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,17 +60,17 @@ class RedirectController {
|
||||||
if (preg_match('%^(@[A-Za-z0-9_.]+)(?:/|$)(.*)%', $m[1], $u)) {
|
if (preg_match('%^(@[A-Za-z0-9_.]+)(?:/|$)(.*)%', $m[1], $u)) {
|
||||||
if ($u[2] == '') {
|
if ($u[2] == '') {
|
||||||
// User profile URL
|
// User profile URL
|
||||||
return '/' . $u[1];
|
return '/' . urlencode($u[1]);
|
||||||
} elseif (preg_match('%^video/(\d+)%', $u[2], $v)) {
|
} elseif (preg_match('%^video/(\d+)%', $u[2], $v)) {
|
||||||
// Video URL
|
// Video URL
|
||||||
return '/' . $u[1] . '/video/' . $v[1];
|
return '/' . urlencode($u[1]) . '/video/' . urlencode($v[1]);
|
||||||
}
|
}
|
||||||
} elseif (preg_match('%^tag/([^ ]+?)(?:/|$)%', $m[1], $t)) {
|
} elseif (preg_match('%^tag/([^ ]+?)(?:/|$)%', $m[1], $t)) {
|
||||||
// Tag URL
|
// Tag URL
|
||||||
return '/tag/' . $t[1];
|
return '/tag/' . urlencode($t[1]);
|
||||||
} elseif (preg_match('%^music/([^ ]+?)(?:/|$)%', $m[1], $m)) {
|
} elseif (preg_match('%^music/([^ ]+?)(?:/|$)%', $m[1], $m)) {
|
||||||
// Music URL
|
// Music URL
|
||||||
return '/music/' . $m[1];
|
return '/music/' . urlencode($m[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue