mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
validation for image url
This commit is contained in:
parent
e94c495434
commit
961a0fb3b9
1 changed files with 11 additions and 1 deletions
|
@ -214,7 +214,7 @@ class Item {
|
|||
* @return string
|
||||
*/
|
||||
public function image_url():string {
|
||||
return $this->image_url;
|
||||
return $this->validate_image_url() ? $this->image_url : '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,4 +269,14 @@ class Item {
|
|||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the image url for PayPal request.
|
||||
*
|
||||
* @return bool true if valid, otherwise false.
|
||||
*/
|
||||
protected function validate_image_url(): bool {
|
||||
$pattern = '/^(https:)([\/|\.|\w|\s|-])*\.(?:jpg|gif|png|jpeg|JPG|GIF|PNG|JPEG)$/';
|
||||
return (bool) preg_match( $pattern, $this->image_url );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue