RFC 4122支持不带连字符的UUID吗?

huangapple go评论51阅读模式
英文:

Does RFC 4122 support unhyphenated UUIDs?

问题

I understand that you want the Chinese translation of the provided text. Here it is:

我理解UUID包含一组字符,按照RFC 4122的8-4-4-4-12字符模式分成5组。示例:123e4567-e89b-12d3-a456-42661417400

我正在使用Google的流行Go库来解析UUID(https://github.com/google/uuid)。这个库特别解析了123e4567-e89b-12d3-a456-42661417400123e4567e89b12d3a456426614174000,没有任何错误。

根据RFC 4122,我应该解析潜在的UUID。但我不确定RFC 4122是否认为123e4567e89b12d3a456426614174000123e4567-e89b-12d3-a456-42661417400同样有效。我在官方文档中没有找到任何关于是否允许使用连接符(-)或无连接符UUID的信息。

请分享您的想法,谢谢。

英文:

I understand that UUID contains a set of characters grouped into 5 groups in an 8-4-4-4-12 character pattern as per RFC 4122. Example: 123e4567-e89b-12d3-a456-42661417400

I am using a popular library by Google for Go to parse UUID (https://github.com/google/uuid). This library in particular parses both 123e4567-e89b-12d3-a456-42661417400 and 123e4567e89b12d3a456426614174000 without any error.

I am supposed to parse a potential UUID as per RFC 4122. But I'm not sure if RFC 4122 considers 123e4567e89b12d3a456426614174000 equally valid as 123e4567-e89b-12d3-a456-42661417400. I haven't found any material on the official documentation that has a SAY whether unhyphenated (or dashed) UUIDs are valid.

Please share your toughts, thanks.

答案1

得分: 5

RFC 4122 定义了 UUID 的字符串表示形式,其中 第 3 节 如下所示:

  UUID 的正式定义使用以下 ABNF [7] 给出:

  UUID                   = time-low "-" time-mid "-"
                           time-high-and-version "-"
                           clock-seq-and-reserved
                           clock-seq-low "-" node

基于此,不带连字符的任何 UUID 都不符合标准。

... 特定库可以解析 123e4567-e89b-12d3-a456-42661417400 和 123e4567e89b12d3a456426614174000 的表示形式而不出错。

并且明确记录了该库能够解析 UUID 的非标准表示形式。引用自 文档

func Parse
func Parse(s string) (UUID, error)
Parse 可以将 s 解码为 UUID 或返回错误。它可以解码 标准 UUID 格式:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 和 urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,以及 Microsoft 编码 {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 和原始十六进制编码:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

英文:

The RFC 4122 defines the string representation for UUID in section 3 as:

  The formal definition of the UUID string representation is
  provided by the following ABNF [7]:

  UUID                   = time-low "-" time-mid "-"
                           time-high-and-version "-"
                           clock-seq-and-reserved
                           clock-seq-low "-" node

Based on this any UUID without hyphens is not conforming to the standard.

> ... This library in particular parses both 123e4567-e89b-12d3-a456-42661417400 and 123e4567e89b12d3a456426614174000 without any error.

And it is explicitly documented as being able to parse non-standard representations for UUID. To cite from the documentation:

> func Parse<br> func Parse(s string) (UUID, error)<br> Parse decodes s
> into a UUID or returns an error. Both the standard UUID forms of
> xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and
> urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as
> the Microsoft encoding {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} and the
> raw hex encoding: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.

答案2

得分: 0

但我不确定RFC 4122是否将123e4567e89b12d3a456426614174000视为与123e4567-e89b-12d3-a456-42661417400同样有效

UUID是一个16字节的二进制值,而不是二进制值的字符串表示。

RFC规定了UUID的标准字符串表示,但这并不意味着RFC之外的其他字符串表示是无效的。

如果您的应用程序需要标准字符串表示的输入,那么应用程序在调用解析之前应该检查字符串。

英文:

> But I'm not sure if RFC 4122 considers 123e4567e89b12d3a456426614174000 equally valid as 123e4567-e89b-12d3-a456-42661417400

A UUID is a 16 byte binary value, not the string representation of the binary value.

The RFC specifies a standard string representation for UUIDs, but that does not make other string representations invalid by the RFC.

If your application requires input in the standard string representation, then the application should check the string before calling Parse.

huangapple
  • 本文由 发表于 2023年5月22日 22:29:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定