Skip to content

Commit

Permalink
テーマ設定の「リンク先URL」欄のルートパスやnullがエラーになる。  レビュー修正
Browse files Browse the repository at this point in the history
入力値の文字列型チェック、空文字の許容、pathの存在確認&正規表現 追加
  • Loading branch information
IwasakiRyuichi committed Jan 30, 2025
1 parent 3ad0405 commit 5f27e0a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion plugins/baser-core/src/Model/Validation/BcValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,23 @@ public static function checkWithJson($string, $key, $regex)
*/
public static function urlCheck($value):bool
{
return preg_match('/^($|\/|\/[a-zA-Z0-9\-]+(\/[a-zA-Z0-9\-]*)*|[a-zA-Z0-9\-\.]+:\/\/[a-zA-Z0-9\-\.]+(\/[a-zA-Z0-9\-\.\/?&=]*)*)$/', $value);

// 文字列チェック
if(!is_string($value)) {
return false;
}

// 空文字は許容
if ($value === '') {
return true;
}

// `parse_url` でパス部分を取得
$parsedUrl = parse_url($value);


// `path` の存在を確認し、スラッシュから始まっているかをチェック
return isset($parsedUrl['path']) && preg_match('/^\/[a-zA-Z0-9\-_\/]*$/', $parsedUrl['path']);
}

}

0 comments on commit 5f27e0a

Please sign in to comment.