Skip to content
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
5 changes: 3 additions & 2 deletions plugins/faustwp/includes/settings/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function sanitize_faustwp_settings( $settings, $option ) {

switch ( $name ) {
case 'frontend_uri':
if ( '' === $value || preg_match( '#http(s?)://(.+)#i', $value ) ) {
if ( '' === $value || ( is_string( $value ) && preg_match( '#http(s?)://(.+)#i', $value ) ) ) {
$settings[ $name ] = esc_url_raw( $value, $protocols );
} else {
$errors[ $name ] = __( 'The Front-end site URL you entered did not appear to be a valid URL. Please enter a valid URL.', 'faustwp' );
Expand Down Expand Up @@ -566,5 +566,6 @@ function trim_frontend_uri_trailing_slash( $value, $name ) {
return $value;
}

return untrailingslashit( $value );
// A front-end URL saved outside the settings screen may be null.
return untrailingslashit( (string) $value );
}
1 change: 1 addition & 0 deletions plugins/faustwp/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
backupGlobals="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class ProcessTelemetryRouteTests extends WP_UnitTestCase
{
private $server;
private $request;
private $route_name;

Expand Down
15 changes: 15 additions & 0 deletions plugins/faustwp/tests/integration/SettingsCallbacksTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace WPE\FaustWP\Tests\Integration;

use function WPE\FaustWP\Settings\sanitize_faustwp_settings;
use function WPE\FaustWP\Settings\trim_frontend_uri_trailing_slash;

class SettingsCallbacksTests extends \WP_UnitTestCase {

Expand Down Expand Up @@ -41,6 +42,20 @@ public function test_sanitize_faustwp_settings_does_not_change_existing_settings
$this->assertSame( $this->init_settings, sanitize_faustwp_settings( $this->init_settings, $this->option ) );
}

public function test_sanitize_faustwp_settings_rejects_a_null_frontend_uri() {
$sanitized = sanitize_faustwp_settings( [ 'frontend_uri' => null ], $this->option );

$this->assertSame( $this->init_settings['frontend_uri'], $sanitized['frontend_uri'] );
$errors = get_settings_errors( $this->option );
$this->assertCount( 1, $errors );
$this->assertEquals( $errors[0]['code'], 'faustwp_invalid_frontend_uri' );
}

public function test_trim_frontend_uri_trailing_slash_handles_a_null_frontend_uri() {
$this->assertSame( '', trim_frontend_uri_trailing_slash( null, 'frontend_uri' ) );
$this->assertSame( 'http://localhost:3000', trim_frontend_uri_trailing_slash( 'http://localhost:3000/', 'frontend_uri' ) );
}

public function test_sanitize_faustwp_settings_allows_valid_frontend_uris() {
$valid_uris = [
// Clean URLs
Expand Down
Loading