Ticket #521 (closed Bug: fixed)

Opened 8 months ago

Last modified 8 months ago

prep_url() fails on valid URL

Reported by: mikexstudios Owned by: Geert
Priority: major Milestone: 2.1.2
Component: Libraries:Validation Version: SVN HEAD
Keywords: validation prep_url Cc:

Description

From r2344, the Validation library's prep_url function is flawed in that valid URLs are not returned (the function only returns corrected URLs; valid URLs are never returned).

I recommend modifying the function to include a 'return $str' at the very end:

	/**
	 * Filter: prep_url. Prepares a URL for valid::url().
	 *
	 * @param   string  possibly incomplete URL
	 * @return  string
	 */
	public function prep_url($str = '')
	{
		if ($str === '' OR $str === 'http://' OR $str === 'https://')
			return '';

		if (substr($str, 0, 7) !== 'http://' AND substr($str, 0, 8) !== 'https://')
			return 'http://'.$str;
			
		//Otherwise, URL is complete:
		return $str;
	}

Change History

Changed 8 months ago by schnoodles

what about more options, for example what if you want it to return https instead of http. and are things like ssh and ftp classified as urls ?

Changed 8 months ago by Shadowhand

  • owner changed from - No owner - to Geert

Changed 8 months ago by Geert

  • keywords prep_url added; prepurl removed
  • status changed from new to closed
  • resolution set to fixed

Fixed in r2357. Good call, mikexstudios.

@schnoodles: the prep_url filter is just a quick function that allows you to, for example, prefill forms with "http://", or accepts URLs like "www.mysite.com" from users, without making valid::url() choke on them. A user can still fill in a "https://" URL or use any other protocol.

Note: See TracTickets for help on using tickets.