Skip to content

byLabel fails if multiple label names start with the given label name #1454

@pythonissam

Description

@pythonissam

ex.) Call byLabel "hobby" "fishing" and if the form has <label for="hobby">hobby</label> and <label for="hobby2">hobby2</label>. Then, it fails with "More than one label contained " ALTHOUGH THEIR NAMES ARE DIFFERENT.

Yesod.Test.byLabel calls nameFromLabel in its definition. nameFromLabel looks up the name of a field based on the contents of the label pointing to it. In its definition, label names which start with label are assigned into mlabel

mlabel = parseHTML body
                $// C.element "label"
                >=> contentContains label

contentContains x c
        | x `T.isInfixOf` T.concat (c $// content) = [c]
        | otherwise = []

Then, the definition follows:

mfor = mlabel >>= attribute "for"

case mfor of
    for:[] -> do
      let mname = parseHTML body
                    $// attributeIs "id" for
                    >=> attribute "name"
      case mname of
        "":_ -> failure $ T.concat
            [ "Label "
            , label
            , " resolved to id "
            , for
            , " which was not found. "
            ]
        name:_ -> return name
        [] -> failure $ "No input with id " <> for
    [] ->
      case filter (/= "") $ mlabel >>= (child >=> C.element "input" >=> attribute "name") of
        [] -> failure $ "No label contained: " <> label
        name:_ -> return name
    _ -> failure $ "More than one label contained " <> label

Here, the first example fails. Apparently, the cause is that we used T.isInfixOf in contentContains and not only "hobby", but also "hobby2" is taken because it contains "hobby" at the beginning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions