From 583d576cdba6c46049f23f2caf36714054d30cc4 Mon Sep 17 00:00:00 2001
From: John Guo <john@johng.cn>
Date: Mon, 9 May 2022 21:26:42 +0800
Subject: [PATCH] remove octal number converting for gconv.Int*/Uint*
 functions; fix issue #1733

---
 database/gdb/gdb_z_mysql_model_test.go | 31 ++++++++++++++++++++++++++
 util/gconv/gconv_int.go                | 15 ++++---------
 util/gconv/gconv_uint.go               |  6 -----
 util/gconv/gconv_z_unit_all_test.go    |  4 ++--
 4 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/database/gdb/gdb_z_mysql_model_test.go b/database/gdb/gdb_z_mysql_model_test.go
index 94259294e8e..d03f0eec7ab 100644
--- a/database/gdb/gdb_z_mysql_model_test.go
+++ b/database/gdb/gdb_z_mysql_model_test.go
@@ -4286,3 +4286,34 @@ func Test_Model_Issue1701(t *testing.T) {
 		t.Assert(value.String(), 100)
 	})
 }
+
+// https://github.com/gogf/gf/issues/1733
+func Test_Model_Issue1733(t *testing.T) {
+	table := "user_" + guid.S()
+	if _, err := db.Exec(ctx, fmt.Sprintf(`
+	    CREATE TABLE %s (
+	        id int(8) unsigned zerofill NOT NULL AUTO_INCREMENT,
+	        PRIMARY KEY (id)
+	    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+	    `, table,
+	)); err != nil {
+		gtest.AssertNil(err)
+	}
+	defer dropTable(table)
+
+	gtest.C(t, func(t *gtest.T) {
+		for i := 1; i <= 10; i++ {
+			_, err := db.Model(table).Data(g.Map{
+				"id": i,
+			}).Insert()
+			t.AssertNil(err)
+		}
+
+		all, err := db.Model(table).OrderAsc("id").All()
+		t.AssertNil(err)
+		t.Assert(len(all), 10)
+		for i := 0; i < 10; i++ {
+			t.Assert(all[i]["id"].Int(), i+1)
+		}
+	})
+}
diff --git a/util/gconv/gconv_int.go b/util/gconv/gconv_int.go
index 63bd7752998..50626da7875 100644
--- a/util/gconv/gconv_int.go
+++ b/util/gconv/gconv_int.go
@@ -97,8 +97,10 @@ func Int64(any interface{}) int64 {
 		if f, ok := value.(iInt64); ok {
 			return f.Int64()
 		}
-		s := String(value)
-		isMinus := false
+		var (
+			s       = String(value)
+			isMinus = false
+		)
 		if len(s) > 0 {
 			if s[0] == '-' {
 				isMinus = true
@@ -116,15 +118,6 @@ func Int64(any interface{}) int64 {
 				return v
 			}
 		}
-		// Octal
-		if len(s) > 1 && s[0] == '0' {
-			if v, e := strconv.ParseInt(s[1:], 8, 64); e == nil {
-				if isMinus {
-					return -v
-				}
-				return v
-			}
-		}
 		// Decimal
 		if v, e := strconv.ParseInt(s, 10, 64); e == nil {
 			if isMinus {
diff --git a/util/gconv/gconv_uint.go b/util/gconv/gconv_uint.go
index 4f8d3b63a7e..fd0c258545e 100644
--- a/util/gconv/gconv_uint.go
+++ b/util/gconv/gconv_uint.go
@@ -104,12 +104,6 @@ func Uint64(any interface{}) uint64 {
 				return v
 			}
 		}
-		// Octal
-		if len(s) > 1 && s[0] == '0' {
-			if v, e := strconv.ParseUint(s[1:], 8, 64); e == nil {
-				return v
-			}
-		}
 		// Decimal
 		if v, e := strconv.ParseUint(s, 10, 64); e == nil {
 			return v
diff --git a/util/gconv/gconv_z_unit_all_test.go b/util/gconv/gconv_z_unit_all_test.go
index ab04223ccc2..87b0f430ff8 100644
--- a/util/gconv/gconv_z_unit_all_test.go
+++ b/util/gconv/gconv_z_unit_all_test.go
@@ -308,7 +308,7 @@ func Test_Int64_All(t *testing.T) {
 	gtest.C(t, func(t *gtest.T) {
 		var any interface{} = nil
 		t.AssertEQ(gconv.Int64("0x00e"), int64(14))
-		t.Assert(gconv.Int64("022"), int64(18))
+		t.Assert(gconv.Int64("022"), int64(22))
 
 		t.Assert(gconv.Int64(any), int64(0))
 		t.Assert(gconv.Int64(true), 1)
@@ -502,7 +502,7 @@ func Test_Uint64_All(t *testing.T) {
 	gtest.C(t, func(t *gtest.T) {
 		var any interface{} = nil
 		t.AssertEQ(gconv.Uint64("0x00e"), uint64(14))
-		t.Assert(gconv.Uint64("022"), uint64(18))
+		t.Assert(gconv.Uint64("022"), uint64(22))
 
 		t.AssertEQ(gconv.Uint64(any), uint64(0))
 		t.AssertEQ(gconv.Uint64(true), uint64(1))