Repository: jhump/protoreflect (go)

Issue:
protoparse: numbers starting with 0 should be octal
According to protoc "Numbers starting with leading zero must be in octal". The [spec seems to agree](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#integer_literals):

```
intLit     = decimalLit | octalLit | hexLit
decimalLit = ( "1" … "9" ) { decimalDigit }
octalLit   = "0" { octalDigit }
hexLit     = "0" ( "x" | "X" ) hexDigit { hexDigit } 
```

example:

```protobuf
message o {
  optional bool f=09;
}

// protoc error:
// a.proto:2:26: Numbers starting with leading zero must be in octal.
// a.proto:2:25: Integer out of range.
```



Pull request description:
protoparse: Treat all numbers starting with 0 as octal
fixes #458

```protobuf
syntax="proto3";
message o {
  bool f=09;
}

// protoc error:
// a.proto:3:11: Numbers starting with leading zero must be in octal.
// a.proto:3:10: Integer out of range.

// protoparse error:
// a.proto:3:9: invalid syntax in octal integer value: 09
```

Patch:
diff --git a/desc/protoparse/lexer.go b/desc/protoparse/lexer.go
index 155126c..482e6e3 100644
--- a/desc/protoparse/lexer.go
+++ b/desc/protoparse/lexer.go
@@ -289,7 +289,7 @@ func (l *protoLex) Lex(lval *protoSymType) int {
 			}
 			// integer! (decimal or octal)
 			base := 10
-			if token[0] == '0' && len(token) > 1 && token[1] >= '0' && token[1] <= '7' {
+			if token[0] == '0' {
 				base = 8
 			}
 			ui, err := strconv.ParseUint(token, base, 64)


Test patch:
diff --git a/desc/protoparse/lexer_test.go b/desc/protoparse/lexer_test.go
index fdf8538..5f67241 100644
--- a/desc/protoparse/lexer_test.go
+++ b/desc/protoparse/lexer_test.go
@@ -261,6 +261,8 @@ func TestLexerErrors(t *testing.T) {
 		{str: "\U0010FFFF", errMsg: "invalid character"},
 		{str: "// foo \x00", errMsg: "invalid control character"},
 		{str: "/* foo \x00", errMsg: "invalid control character"},
+		{str: "09", errMsg: "invalid syntax in octal integer value: 09"},
+		{str: "0f", errMsg: "invalid syntax in octal integer value: 0f"},
 	}
 	for i, tc := range testCases {
 		l := newTestLexer(strings.NewReader(tc.str))
diff --git a/internal/testprotos/make_protos.sh b/internal/testprotos/make_protos.sh
index b66d229..66b4a95 100755
--- a/internal/testprotos/make_protos.sh
+++ b/internal/testprotos/make_protos.sh
@@ -15,6 +15,12 @@ case "${PROTOC_OS}" in
     exit 1
 esac
 
+# This is for macs with M1 chips. Precompiled binaries for osx/amd64 are not available for download, so for that case
+# we download the x86_64 version instead. This will work as long as rosetta2 is installed.
+if [ "$PROTOC_OS" = "osx" ] && [ "$PROTOC_ARCH" = "arm64" ]; then
+  PROTOC_ARCH="x86_64"
+fi
+
 PROTOC="./protoc/bin/protoc"
 
 if [[ "$(${PROTOC} --version 2>/dev/null)" != "libprotoc ${PROTOC_VERSION}" ]]; then