Skip to content

class and rel attributes only split on single spaces instead of ASCII whitespace, and duplicate h-* types are kept #514

Open

Description

@trackoor

Describe the bug

class and rel attributes are tokenized with .split(" ") instead of splitting on HTML ASCII whitespace (\t, \n, \f, \r, and space) and ignoring empty tokens. When a class or rel attribute wraps across lines or contains tabs or extra spaces, class names stick to adjacent whitespace and fail to match microformat root/property patterns, while rels and rel-urls record keys containing newlines or "". In addition, repeated h-* root classes on the same element are not deduplicated in item.type as required by the microformats2 parsing specification.

To Reproduce

HTML input:

<div class="
  h-card
  p-author
">Jane</div>
<div class="h-card h-card">Alex</div>
<a rel="me
  noopener" href="http://example.com/jane">Profile</a>

Run with npm i microformats-parser@2.0.6 && node repro.mjs:

import { mf2 } from "microformats-parser";

const html = `<div class="
  h-card
  p-author
">Jane</div>
<div class="h-card h-card">Alex</div>
<a rel="me
  noopener" href="http://example.com/jane">Profile</a>`;

console.log(JSON.stringify(mf2(html, { baseUrl: "http://example.com/" }), null, 2));

Actual JSON output:

{
  "rels": {
    "me\n": [
      "http://example.com/jane"
    ],
    "": [
      "http://example.com/jane"
    ],
    "noopener": [
      "http://example.com/jane"
    ]
  },
  "rel-urls": {
    "http://example.com/jane": {
      "rels": [
        "",
        "me\n",
        "noopener"
      ],
      "text": "Profile"
    }
  },
  "items": [
    {
      "type": [
        "h-card",
        "h-card"
      ],
      "properties": {
        "name": [
          "Alex"
        ]
      }
    }
  ]
}

Expected behavior

Correct JSON output:

{
  "rels": {
    "me": [
      "http://example.com/jane"
    ],
    "noopener": [
      "http://example.com/jane"
    ]
  },
  "rel-urls": {
    "http://example.com/jane": {
      "rels": [
        "me",
        "noopener"
      ],
      "text": "Profile"
    }
  },
  "items": [
    {
      "type": [
        "h-card"
      ],
      "properties": {
        "name": [
          "Jane"
        ]
      }
    },
    {
      "type": [
        "h-card"
      ],
      "properties": {
        "name": [
          "Alex"
        ]
      }
    }
  ]
}

Additional context

Tested on microformats-parser@2.0.6 and main (aa91899) on Node.js v26.13.0, and confirmed in the online demo at https://microformats.github.io/microformats-parser/ (which does not support URL parameters for pre-filling input).

getClassNames, hasRelIntersect, and getRelIntersect in src/helpers/attributes.ts and parseRel in src/rels/rels.ts call .split(" ") without filtering empty strings, and getMicroformatType in src/microformats/parse.ts sorts h-* class names without deduplicating them (also covered in microformat-tests under tests/microformats-v2-unit/names/, which test/scenarios.spec.ts does not load yet).

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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