Skip to content

Load proto file from different host goes wrong. #941

Open
@zgayjjf

Description

@zgayjjf

protobuf.js version: 6.8.0

I am trying to load .proto file in browser.
Proto files and html file are stored in different host. However, protobufjs can not load correct path.

For example, my html is http://www.qq.com/testhtml/index.html

protobuf.load('http://www.baidu.com/testproto/test.proto').then(function (root) {console.log(root)})

Code above will finally load http://www.qq.com/www.baidu.com/testproto/test.proto

I tried //www.baidu.com/testproto/test.proto and //www.baidu.com/testproto/test.proto, but neither worked.

I belive normalize function shall be rewrite.
image

path.normalize = function normalize(path) {
    // if a path is started with http or https, it should not be normalize
    if (path.indexOf('http') === 0) {
        return path
    }
    path = path.replace(/\\/g, "/")
               .replace(/\/{2,}/g, "/");
    var parts    = path.split("/"),
        absolute = isAbsolute(path),
        prefix   = "";
    if (absolute)
        prefix = parts.shift() + "/";
    for (var i = 0; i < parts.length;) {
        if (parts[i] === "..") {
            if (i > 0 && parts[i - 1] !== "..")
                parts.splice(--i, 2);
            else if (absolute)
                parts.splice(i, 1);
            else
                ++i;
        } else if (parts[i] === ".")
            parts.splice(i, 1);
        else
            ++i;
    }
    return prefix + parts.join("/");
}

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