Skip to content

Type Name Sanitization with Mixed Special Characters #62

@houstonhaynes

Description

@houstonhaynes

Type names containing both hyphens AND underscores (e.g., workers-kv_key_name) were inconsistently sanitized, causing "type not found" compilation errors.

Problem

Hawaii's original sanitizeTypeName function only handled one transformation at a time:

// Original (buggy):
let sanitizeTypeName (name: string) =
    if name.Contains "_" then
        name.Split('_') |> String.concat ""
    elif name.Contains "-" then
        name.Split('-') |> String.concat ""
    else name

// Result: "workers-kv_key_name"
//   → Removes underscores → "workers-kvkeyname"
//   → But doesn't remove hyphens!

CloudflareFS Workaround

We fixed this in local fork with cumulative transformations:

// Fixed version:
let sanitizeTypeName (name: string) =
    let mutable result = name
    if result.Contains "_" then result <- result.Split('_') |> String.concat ""
    if result.Contains "-" then result <- result.Split('-') |> String.concat ""
    if result.Contains "." then result <- result.Split('.') |> String.concat ""
    result

// Result: "workers-kv_key_name" → "workerskvkeyname" 

Recommendation

Again I may upstream my patch. The approach removes all special characters, regardless of order. But again, it may be "ugly" and hurt readability. A more systematic/elegant approach may supercede what I did to get through my POC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions