-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not allow to extend same field twice to prevent the error (#1784
) * do not allow to extend same field twice to prevent the error * Ignore gitpod config * unit test for issue #1783 * using existing test file
- Loading branch information
1 parent
644d588
commit 14f0536
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ coverage/ | |
sandbox/ | ||
.nyc_output | ||
dist/ | ||
.gitpod.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var path = require("path"); | ||
var tape = require("tape"); | ||
var protobuf = require("../index"); | ||
// to extend Root | ||
require("../ext/descriptor"); | ||
tape.test("extensions", function (test) { | ||
// load document with extended field imported multiple times | ||
var root = protobuf.loadSync(path.resolve(__dirname, "data/test.proto")); | ||
root.resolveAll(); | ||
// convert to Descriptor Set | ||
var decodedDescriptorSet = root.toDescriptor("proto3"); | ||
// load back from descriptor set | ||
var root2 = protobuf.Root.fromDescriptor(decodedDescriptorSet); | ||
test.pass("should parse and resolve without errors"); | ||
test.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import path = require("path"); | ||
import * as tape from "tape"; | ||
|
||
import * as protobuf from "../index"; | ||
import { IFileDescriptorSet } from "../ext/descriptor"; | ||
// to extend Root | ||
require("../ext/descriptor"); | ||
|
||
interface Descriptor { | ||
toDescriptor( | ||
protoVersion: string | ||
): protobuf.Message<IFileDescriptorSet> & IFileDescriptorSet; | ||
fromDescriptor( | ||
descriptor: IFileDescriptorSet | protobuf.Reader | Uint8Array | ||
): protobuf.Root; | ||
} | ||
|
||
tape.test("extensions", function (test) { | ||
// load document with extended field imported multiple times | ||
const root = protobuf.loadSync(path.resolve(__dirname, "data/test.proto")); | ||
root.resolveAll(); | ||
|
||
// convert to Descriptor Set | ||
const decodedDescriptorSet = (root as unknown as Descriptor).toDescriptor( | ||
"proto3" | ||
); | ||
|
||
// load back from descriptor set | ||
const root2 = (protobuf.Root as unknown as Descriptor).fromDescriptor( | ||
decodedDescriptorSet | ||
); | ||
|
||
test.pass("should parse and resolve without errors"); | ||
test.end(); | ||
}); |