From 88be0f30f48a10837e2aaf4fe2f5662999d2a57e Mon Sep 17 00:00:00 2001 From: Josh Cunningham Date: Tue, 30 Jul 2019 14:36:06 -0700 Subject: [PATCH] Change CDN URL field to text to avoid browser validation --- lib/admin/WP_Auth0_Admin_Advanced.php | 10 ---------- lib/admin/WP_Auth0_Admin_Appearance.php | 13 ++++++++++++- tests/testOptionLockCdn.php | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/admin/WP_Auth0_Admin_Advanced.php b/lib/admin/WP_Auth0_Admin_Advanced.php index e80546c8..fcec33f9 100644 --- a/lib/admin/WP_Auth0_Admin_Advanced.php +++ b/lib/admin/WP_Auth0_Admin_Advanced.php @@ -579,16 +579,6 @@ public function basic_validation( $old_options, $input ) { $input['auth0_implicit_workflow'] = ( isset( $input['auth0_implicit_workflow'] ) ? $input['auth0_implicit_workflow'] : 0 ); $input['force_https_callback'] = ( isset( $input['force_https_callback'] ) ? $input['force_https_callback'] : 0 ); - $input['custom_cdn_url'] = empty( $input['custom_cdn_url'] ) ? 0 : 1; - - $input['cdn_url'] = empty( $input['cdn_url'] ) ? WPA0_LOCK_CDN_URL : sanitize_text_field( $input['cdn_url'] ); - - // If an invalid URL is used, default to previously saved (if there is one) or default URL. - if ( ! filter_var( $input['cdn_url'], FILTER_VALIDATE_URL ) ) { - $input['cdn_url'] = isset( $old_options['cdn_url'] ) ? $old_options['cdn_url'] : WPA0_LOCK_CDN_URL; - self::add_validation_error( __( 'The Lock JS CDN URL used is not a valid URL.', 'wp-auth0' ) ); - } - $input['migration_ips_filter'] = ( ! empty( $input['migration_ips_filter'] ) ? 1 : 0 ); $input['valid_proxy_ip'] = ( isset( $input['valid_proxy_ip'] ) ? $input['valid_proxy_ip'] : null ); diff --git a/lib/admin/WP_Auth0_Admin_Appearance.php b/lib/admin/WP_Auth0_Admin_Appearance.php index ca0d5c11..b4e858c0 100644 --- a/lib/admin/WP_Auth0_Admin_Appearance.php +++ b/lib/admin/WP_Auth0_Admin_Appearance.php @@ -165,7 +165,7 @@ public function render_custom_cdn_url( $args = array() ) { * @see add_settings_field() */ public function render_cdn_url( $args = array() ) { - $this->render_text_field( $args['label_for'], $args['opt_name'], 'url' ); + $this->render_text_field( $args['label_for'], $args['opt_name'] ); $this->render_field_description( __( 'This should point to the latest Lock JS available in the CDN and rarely needs to change', 'wp-auth0' ) ); @@ -482,6 +482,17 @@ public function basic_validation( $old_options, $input ) { $input['language_dictionary'] = isset( $old_options['language_dictionary'] ) ? $old_options['language_dictionary'] : ''; } } + + $input['custom_cdn_url'] = empty( $input['custom_cdn_url'] ) ? 0 : 1; + + $input['cdn_url'] = empty( $input['cdn_url'] ) ? WPA0_LOCK_CDN_URL : sanitize_text_field( $input['cdn_url'] ); + + // If an invalid URL is used, default to previously saved (if there is one) or default URL. + if ( ! filter_var( $input['cdn_url'], FILTER_VALIDATE_URL ) ) { + $input['cdn_url'] = isset( $old_options['cdn_url'] ) ? $old_options['cdn_url'] : WPA0_LOCK_CDN_URL; + self::add_validation_error( __( 'The Lock JS CDN URL used is not a valid URL.', 'wp-auth0' ) ); + } + return $input; } diff --git a/tests/testOptionLockCdn.php b/tests/testOptionLockCdn.php index bf777aeb..334eac50 100644 --- a/tests/testOptionLockCdn.php +++ b/tests/testOptionLockCdn.php @@ -27,7 +27,7 @@ class TestOptionLockCdn extends WP_Auth0_Test_Case { */ public static function setUpBeforeClass() { parent::setUpBeforeClass(); - self::$admin = new WP_Auth0_Admin_Advanced( self::$opts, new WP_Auth0_Routes( self::$opts ) ); + self::$admin = new WP_Auth0_Admin_Appearance( self::$opts, new WP_Auth0_Routes( self::$opts ) ); } /** @@ -122,7 +122,7 @@ public function testThatLockCdnUrlFieldDisplaysProperly() { ); // Input should be a checkbox. - $this->assertEquals( 'url', $input->item( 0 )->getAttribute( 'type' ) ); + $this->assertEquals( 'text', $input->item( 0 )->getAttribute( 'type' ) ); // Check that saving a custom domain appears in the field value. self::$opts->set( $field_args['opt_name'], 'https://auth0.com' );