Skip to content

Relative links passing through Sanitizer::httpUrl() default to http in all cases #2128

@romaincazier

Description

@romaincazier

Hi,

While updating my PageMjmlToHtml module, I’ve been wondering if Sanitizer::httpUrl() shouldn’t default to https in respect to $config->https?

Otherwise it could be an added option to Sanitizer::url(), something like forceHttps.

You would need to edit these lines and here is a suggestion:

if(!$scheme) {
	$https = $this->wire()->config->https ? "https" : "http";

	/* ... */

	if($options['allowRelative']) {
		/* ... */
		if($dotPos && $slashPos > $dotPos && preg_match($regex, $value, $matches)) {
			/* ... */
			$value = $this->filterValidateURL("$https://$value", $options); // add scheme for validation

		} else if($options['allowQuerystring']) {
			/* ... */
			$fake = "$https://processwire.com/";
			/* ... */
		}
	} else {
		/* ... */
		$value = $this->filterValidateURL("$https://$value", $options);
	}

	if(!$options['requireScheme']) {
		/* ... */
		$value = str_replace("$https://", '', $value);
	}
} else if($scheme !== 'tel') { /* ... */

Thanks for considering.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions