Jump to content

Domain orders forms getSld() returns odd results


Recommended Posts

Posted (edited)

Referring to the method getSld() in <Blesta 4.2.2>/plugins/order/lib/order_types/domain/order_type_domain.php

This method doesn't handle domain searches as gracefully as it could.

Search: www.something.com (.com checkbox selected)

  • something.com
  • somethingwww..com

Search: www.something (.com checkbox selected)

  • www.com

Search: something.com (.com checkbox selected)

  • something.com

Search: something (.com checkbox selected)

  • something.com

 

I'm not sure how this could be rectified by changing the existing regex, but I've found something like the following to handle all the above inputs to return something sensible

	function getSld($domain) {
		$parts = explode(".", $domain);
		if (count($parts) == 1) {
			return $parts[0];
		}
		
		return $parts[0] == "www" ? $parts[1] : $parts[0];
	}

	// Mentioned test cases
	foreach ([
		'www.something.com', 
		'www.something', 
		'something.com', 
		'something'] as $search) {
	
		echo "$search: ", getSld($search), "<br>";
	}

	/* Output
	www.something.com: something
	www.something: something
	something.com: something
	something: something
	*/

 

Edited by texh
Specify Blesta version
Posted

I just tried in my Blesta installation and got the same (weird) result. I think the solution you're proposing is pretty good, I did some testing even using Punnycode domains and it seems to work perfectly.

Screen_Shot_2018_05_24_at_7_53_13_PM.png

  • 4 weeks later...
  • Tyson locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...