Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load proto file from different host goes wrong. #941

Open
zgayjjf opened this issue Nov 15, 2017 · 2 comments
Open

Load proto file from different host goes wrong. #941

zgayjjf opened this issue Nov 15, 2017 · 2 comments

Comments

@zgayjjf
Copy link

zgayjjf commented Nov 15, 2017

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("/");
}
@dcodeIO
Copy link
Member

dcodeIO commented Nov 24, 2017

Currently, load doesn't support remote urls. In the browser, it merely tries to mimic node's fs module.

@forrestli74
Copy link

forrestli74 commented Nov 13, 2020

This is actually resolved here: #1351
But we need to bump the version of @protobufjs/path.
Can someone help?

(edit): the PR will only fix for "//www.baidu.com/testproto/test.proto", but not "http://www.baidu.com/testproto/test.proto"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants