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

parser: doesn't support repeated option value #1329

Open
zonyitoo opened this issue Dec 11, 2019 · 4 comments
Open

parser: doesn't support repeated option value #1329

zonyitoo opened this issue Dec 11, 2019 · 4 comments

Comments

@zonyitoo
Copy link

protobuf.js version: 5.0.3

message MessageWithRepeatedOption {
    optional int32 value = 1 [(customized_option) = { in: [1, 2, 3] }];
}

We call it with pbjs.main (command line API).

Error: Error: no such Type or Enum 'mmgameauthadminweb.AddSubAuthSetResponse' in Type .mmgameauthadmindbmq.AddSubAuthSetResponse
    at Object.<anonymous> (/Users/littledu/WGFE/weadmin/backend/dist/helpers/apiManage/descGenerator.js:339:27)
    at step (/Users/littledu/WGFE/weadmin/backend/dist/helpers/apiManage/descGenerator.js:43:23)
    at Object.throw (/Users/littledu/WGFE/weadmin/backend/dist/helpers/apiManage/descGenerator.js:24:53)
    at rejected (/Users/littledu/WGFE/weadmin/backend/dist/helpers/apiManage/descGenerator.js:16:65)

The stacktrace isn't very useful. But after deleted in: [1, 2, 3] in .proto file, everything worked Ok.

Related code: https://github.com/protobufjs/protobuf.js/blob/master/src/parse.js#L556-L577 . It seems that parser doesn't handle [ and ].

@natiz
Copy link

natiz commented Dec 15, 2019

+1

natiz added a commit to natiz/protobuf.js that referenced this issue Dec 15, 2019
@ZiyunHe
Copy link

ZiyunHe commented Dec 23, 2019

+1

@ZiyunHe
Copy link

ZiyunHe commented Dec 23, 2019

wrote a simple hack:

added new function:

function readArray() {
	var values = [];
        if (skip("[", true)) {
            do {
                var token = next();
                token = parseInt(token, 10);
                values.push(token);
            } while (skip(",", true));
            skip("]");
        }
        return values;
    }

change parseOptionValue function to following:

function parseOptionValue(parent, name) {
        if (skip("{", true)) { // { a: "foo" b { c: "bar" } }
            do {
                /* istanbul ignore if */
                if (!nameRe.test(token = next()))
                    throw illegal(token, "name");

                if (peek() === "{")
                    parseOptionValue(parent, name + "." + token);
                else {
                    skip(":");
                    if (peek() === "{")
                        parseOptionValue(parent, name + "." + token);
	            else if (peek() === "[") {   // <---------------------- check [
			setOption(parent, name + "." + token, readArray(true));
                    } else
                        setOption(parent, name + "." + token, readValue(true));
                }
                skip(",", true);
            } while (!skip("}", true));
        } else
            setOption(parent, name, readValue(true));
        // Does not enforce a delimiter to be universal
    }

@eyalpost
Copy link
Contributor

eyalpost commented Jan 6, 2020

The format for options is not JSON which is why [ is invalid there. In your case, the option should have written like this (This is called protobuf text format):

message MessageWithRepeatedOption {
    optional int32 value = 1 [(customized_option) = { in: 1 in: 2 in: 3 }];
}

and altough the parser would not fail in this case, it will also not parse it correctly. There's a PR waiting for a long time now to be reviewed which fixes this: #1256

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

No branches or pull requests

4 participants