Skip to content

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

Description

@ShareInWorld

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIt is confirmed a bug, but don't worry, we'll handle it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions