Skip to content

Phalcon\Url::get and double slashes #14331

Closed
@scrnjakovic

Description

@scrnjakovic

The implementation of this method in v3.4 may return links like:
https://www.example.com//images/booya.jpg

I see that this has been reported and fixed for v4 in #13495

However, why don't we utilize our own helper and replace these 8 lines

cphalcon/phalcon/Url.zep

Lines 166 to 174 in e78ab44

if substr(baseUri, -1) == "/" && strlen(strUri) > 2 && strUri[0] == '/' && strUri[1] != '/' {
let uri = baseUri . substr(strUri, 1);
} else {
if baseUri == "/" && strlen(strUri) == 1 && strUri[0] == '/' {
let uri = baseUri;
} else {
let uri = baseUri . strUri;
}
}

with

let uri = \Phalcon\Helper\Str::reduceSlashes(baseUri . strUri);

furthermore, we can reduce the overhead of invoking an extra function and directly use

let uri = preg_replace("#(?<!:)//+#", "/", baseUri . strUri);

The only scenario in which this wouldn't work is if we passed an url with relative protocols like //netdna.bootstrapcdn.com/twitter-bootstrap/2.3.4/css/bootstrap-combined.min.css but in that case, that wouldn't be a local URL, therefore it does not pose a problem.

cc @niden @sergeyklay @Jurigag

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhancement to the framework

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions