Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

現在のカゴの中 [戻る]ボタン 購入手続きへ遷移することがある #803 (#806 を含む) #814

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions data/class/SC_Initial.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function init()
$this->resetSuperglobalsRequest(); // stripslashesDeepGpc メソッドより後で実行
$this->setTimezone(); // 本当はエラーハンドラーより先に読みたい気も
$this->normalizeHostname(); // defineConstants メソッドより後で実行
$this->compatPhp();
}

/**
Expand Down Expand Up @@ -558,4 +559,41 @@ public function normalizeHostname()
SC_Response_Ex::sendRedirect($correct_url);
}
}

/**
* PHPバージョン互換処理
*
* @deprecated https://github.com/EC-CUBE/ec-cube2/issues/681 が実現したら、外部ライブラリへ移行して、削除する予定。
* @return void
*/
function compatPhp()
{
if (!function_exists('str_starts_with')) {
/**
* 文字列が指定された部分文字列で始まるかを調べる。(for PHP < 8)
*
* @param string $haystack
* @param string $needle
* @return bool
*/
function str_starts_with($haystack, $needle) {
nanasess marked this conversation as resolved.
Show resolved Hide resolved
return strncmp($haystack, $needle, strlen($needle)) === 0;
}
}

if (!function_exists('str_ends_with')) {
/**
* 文字列が、指定された文字列で終わるかを調べる。(for PHP < 8)
*
* @param string $haystack
* @param string $needle
* @return bool
*/
function str_ends_with($haystack, $needle) {
$needle_len = strlen($needle);

return substr($haystack, - $needle_len, $needle_len) === $needle;
}
}
}
}
7 changes: 2 additions & 5 deletions data/class/SC_Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,8 @@ public static function sendRedirect($location, $arrQueryString = array(), $inher
$url = $netUrl->getUrl();
}

$pattern = '/^(' . preg_quote(HTTP_URL, '/') . '|' . preg_quote(HTTPS_URL, '/') . ')/';

// アプリケーション外へのリダイレクトは扱わない
if (preg_match($pattern, $url) === 0) {
trigger_error('', E_USER_ERROR);
if (!SC_Utils_Ex::isInternalUrl($url)) {
trigger_error('アプリケーション外へのリダイレクトは扱わない: ' . var_export($url, true), E_USER_ERROR);
}

$netUrl = new Net_URL($url);
Expand Down
36 changes: 23 additions & 13 deletions data/class/pages/cart/LC_Page_Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,32 @@ public function lfUpdateOrderTempid($pre_uniqid, $uniqid)
*/
public function lfGetCartPrevUrl(&$session, $referer)
{
if (!preg_match('/cart/', $referer)) {
if (!empty($session['cart_referer_url'])) {
$session['cart_prev_url'] = $session['cart_referer_url'];
unset($session['cart_referer_url']);
} else {
if (preg_match('/entry/', $referer)) {
$session['cart_prev_url'] = HTTPS_URL . 'entry/kiyaku.php';
} else {
$session['cart_prev_url'] = $referer;
}
// 妥当性チェック
if (!SC_Utils_Ex::isInternalUrl($referer)) {
return;
}

// 除外ページの場合、何もせず終了する。
$arrExclude = array(
ROOT_URLPATH . 'shopping/',
ROOT_URLPATH . 'cart/',
);

// リファラーから path を切り出す。
$netURL = new Net_URL($referer);
$referer_path = $netURL->path;

foreach ($arrExclude as $start) {
if (str_starts_with($referer_path, $start)) {
return;
}
}
// 妥当性チェック
if (!SC_Utils_Ex::sfIsInternalDomain($session['cart_prev_url'])) {
$session['cart_prev_url'] = '';

if (str_starts_with($referer_path, ROOT_URLPATH . 'entry/')) {
$referer = HTTPS_URL . 'entry/kiyaku.php';
}

$session['cart_prev_url'] = $referer;
}

/**
Expand Down
9 changes: 1 addition & 8 deletions data/class/pages/products/LC_Page_Products_Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,7 @@ public function action()
case 'select':
case 'select2':
case 'selectItem':
/**
* モバイルの数量指定・規格選択の際に、
* $_SESSION['cart_referer_url'] を上書きさせないために、
* 何もせずbreakする。
*/
// nop
break;

default:
Expand Down Expand Up @@ -687,9 +683,6 @@ public function doAddFavoriteSphone(SC_Customer $objCustomer)
*/
public function doDefault()
{
// カート「戻るボタン」用に保持
$netURL = new Net_URL();
$_SESSION['cart_referer_url'] = $netURL->getURL();
}

/**
Expand Down
5 changes: 0 additions & 5 deletions data/class/pages/products/LC_Page_Products_List.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,6 @@ public function doDefault(&$objProduct, &$objFormParam)
SC_Response_Ex::actionExit();
}
$js_fnOnLoad .= $this->lfSetSelectedData($this->arrProducts, $this->arrForm, $arrErr, $target_product_id);
} else {
// カート「戻るボタン」用に保持
$netURL = new Net_URL();
//該当メソッドが無いため、$_SESSIONに直接セット
$_SESSION['cart_referer_url'] = $netURL->getURL();
}

$this->tpl_javascript .= 'function fnOnLoad() {' . $js_fnOnLoad . '}';
Expand Down
11 changes: 11 additions & 0 deletions data/class/util/SC_Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,17 @@ public static function sfIsInternalDomain($url)
return true;
}

/**
* 指定されたURLはアプリケーション内部のものか
*
* @param string $url
* @return boolean
*/
public static function isInternalUrl($url)
{
return str_starts_with($url, HTTPS_URL) || str_starts_with($url, HTTP_URL);
}

/**
* パスワードのハッシュ化
*
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ parameters:
-
message: "#^Variable \\$SJIS_widths might not be defined\\.$#"
path: data/class/helper/SC_Helper_FPDI.php
-
message: "#^Inner named functions are not supported by PHPStan\\.#"
path: data/class/SC_Initial.php
Loading