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

contrib/drivers/pgsql/pgsql_convert.go: If the byte type data contains 0x5D, it will be forcibly converted to 0x7D, causing problems with the stored data. #4231

Open
ShareInWorld opened this issue Apr 2, 2025 · 0 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@ShareInWorld
Copy link

ShareInWorld commented Apr 2, 2025

Go version

go 1.22.4

GoFrame version

gf 2.9.0

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

The image data contains 0x5D with bytea type.

What did you see happen?

It will be forcibly converted to 0x7D.

What did you expect to see?

This causes image parsing to fail by the function in the file contrib/drivers/pgsql/pgsql_convert.go.

func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fieldValue interface{}) (interface{}, error) {
	if g.IsNil(fieldValue) {
		return d.Core.ConvertValueForField(ctx, fieldType, fieldValue)
	}

	var fieldValueKind = reflect.TypeOf(fieldValue).Kind()

	if fieldValueKind == reflect.Slice {
		// For pgsql, json or jsonb require '[]'
		if !gstr.Contains(fieldType, "json") {
			if fileBytes, ok := fieldValue.([]byte); ok && fieldType == "bytea" {
				fieldValue = fileBytes
			} else {
				fieldValue = gstr.ReplaceByMap(gconv.String(fieldValue),
					map[string]string{
						"[": "{",
						"]": "}",
					},
				)
			}
		}
	}
	return d.Core.ConvertValueForField(ctx, fieldType, fieldValue)
}
@ShareInWorld ShareInWorld added the bug It is confirmed a bug, but don't worry, we'll handle it. label Apr 2, 2025
@ShareInWorld ShareInWorld changed the title contrib/drivers/pgsql/pgsql_convert.go: If the byte type data contains 0x5D, it will be forcibly converted to 0x7D, causing problems with the stored data. Translate it contrib/drivers/pgsql/pgsql_convert.go: If the byte type data contains 0x5D, it will be forcibly converted to 0x7D, causing problems with the stored data. Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

1 participant