Skip to content

mime: FormatMediaType inconsistent results #8115

@gopherbot

Description

@gopherbot

by anton.hendriks:

After switching to the go 1.3 beta mime.FormatMediaType has started giving inconsistent
results. This is obviously a result of the map parameter and up till now we've just been
lucky to pass small enough maps that haven't been randomized.

The function produces output from a long chain of processing and having the output
consistent simplifies testing considerably. We usually solve this problem by iterating
over a sorted list of the map keys rather than the map itself.

Proposed fix. Replace line 34 of src/pkg/mime/mediatype.go with the following.

        attributes := make([]string, 0, len(param))
    for a, _ := range param {
        attributes = append(attributes, a)
    }
    sort.Strings(attributes)

    for attribute, _ := range attributes {
        value := param[attribute]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions