Skip to content

Skip empty funder and creator entries in DataCite XML - #466

Merged
neuromechanist merged 2 commits into
devfrom
feature/issue-459-datacite-empty-fields
May 14, 2026
Merged

neuromechanist merged 2 commits into
devfrom
feature/issue-459-datacite-empty-fields

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #459.

Summary

EZID validates submitted DataCite XML against the kernel-4 XSD, which
enforces minLength=1 on <funderName>, <creatorName>, and
<contributorName>. When BIDS Funding or Authors contained an
empty or whitespace-only string, bidsToDataCite() emitted
<funderName/> / <creatorName/> and EZID rejected the entire
DataCite document, failing the DOI mint.

Fix is filtered at two layers:

  1. Source (bidsToDataCite) — trim and drop empty entries from
    BIDS Funding, enrichment fundingInfo, BIDS Authors, and the
    optional uploaderName contributor before they ever reach the XML
    builder. Whitespace is normalized via .trim() on the surviving
    funder names.
  2. Defense (buildDataCiteXml) — filter again at emit time so a
    direct caller that built DataCiteMetadata manually (admin
    tooling, future LLM-enrich path) can't bypass the source filter.
    The funders block is skipped entirely if every entry is junk; the
    creators block throws (matches the existing "at least one creator"
    contract). Contributors silently drop empty entries (the XML block
    is already optional).

The existing XSD-min-length validations on <title> and <publisher>
were already covered by the early-validation checks at the top of
buildDataCiteXml, so no new guards are needed there.

Test plan

  • bun test test/datacite.test.ts — 128/128 pass (9 new tests
    cover: funder filter with mixed valid/empty, all-empty funder block
    drop, contributor filter, all-empty creator throw, mixed creator
    filter, BIDS funding source filter, enrichment fundingInfo source
    filter, BIDS Authors source filter, and the symmetric scenario from
    the issue reproduction).
  • cd backend && bun run typecheck
  • bun run build
  • Wider regression sweep across datacite, manifest,
    llm-enrich-ref-validation, license-provenance, ezid, and
    doi-orcid-discovery test files: 262/262 pass.

@github-actions

github-actions Bot commented May 14, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR466

Version: 0.8.14-PR466.a31c196
Commit: a31c196


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR #466 Review — Skip empty funder/creator entries in DataCite XML

Summary

Tests: 128/128 pass. Typecheck clean. The two-layer fix is correct in intent and addresses the root cause. A few gaps remain.


Critical (0)

None. The primary EZID rejection scenario (empty <funderName/>) is fixed.


Important (2)

1. awardNumber / awardTitle share the same minLength=1 constraint and are not filtered
[backend/src/services/datacite.ts, lines 1050–1055]

The DataCite kernel-4 XSD uses nonemptyString (minLength=1) for <awardNumber> and <awardTitle> just as it does for <funderName>. The emission guards are plain truthiness checks:

if (fund.awardNumber) { … escapeXml(fund.awardNumber) … }
if (fund.awardTitle)  { … escapeXml(fund.awardTitle) … }

A whitespace-only awardNumber or awardTitle (e.g., " ") is truthy and passes, emitting <awardNumber> </awardNumber> which EZID will reject. The same trimming pattern applied to funderName should be applied here:

if (fund.awardNumber?.trim()) {
  lines.push(`      <awardNumber${uriAttr}>${escapeXml(fund.awardNumber.trim())}</awardNumber>`);
}
if (fund.awardTitle?.trim()) {
  lines.push(`      <awardTitle>${escapeXml(fund.awardTitle.trim())}</awardTitle>`);
}

2. uploaderName contributor: guard checks .trim() but pushes the untrimmed value
[backend/src/services/datacite.ts, line 1472 and 1481]

The guard enrichment.uploaderName.trim().length > 0 correctly blocks empty/whitespace names, but the name pushed into contributors is the untrimmed original. A uploaderName of " yahya " would pass the guard, and the defense layer in buildDataCiteXml would also pass it (since .trim().length > 0), resulting in <contributorName> yahya </contributorName> in the XML. While EZID's minLength check would be satisfied, the surrounding spaces are unexpected. The fix is to push enrichment.uploaderName.trim() as the name. The BIDS funding path correctly calls .trim() on the stored value (line 1514); same pattern should apply here.


Suggestions (3)

3. Two-layer design: source-layer is NOT dead code; both layers serve distinct purposes

This is intentional and correct. The source-layer filter in bidsToDataCite prevents junk data propagating into the DataCiteMetadata object (e.g., into D1, into .nemar/metadata.json), while the defense-layer in buildDataCiteXml protects against direct callers (admin tooling, future LLM-enrich path, tests) that construct DataCiteMetadata manually. The design is sound. The comments explain this well.

4. The "throws on all-empty creators" path propagates as an uncaught exception in all callers

buildDataCiteXml throws when all creator names are empty. Callers in doi.ts (lines 189, 298, 350) call this synchronously inside async functions without a try/catch around this specific throw — the error will bubble up through the Worker and become a 500. This is consistent with the existing behavior for other mandatory-field throws (identifier, publisher, publicationYear), so it is not a regression. However, since bidsToDataCite already inserts { name: "(:unav)" } as a fallback when the author list is empty, the all-empty-creators throw in buildDataCiteXml can only be hit by a direct caller that builds a DataCiteMetadata with all-empty creator names. No action needed, but worth noting: if you ever want a recoverable error here, the caller would need to catch it.

5. title field has a whitespace-only gap (pre-existing, not introduced by this PR)

In bidsToDataCite, the title is computed as:

const title = (typeof rawName === "string" ? rawName : undefined) || datasetId;

A rawName of " " (whitespace) is truthy, so title = " ", and titles: [" "] passes the titles.length > 0 guard in buildDataCiteXml. The emitted <title> </title> would fail EZID's minLength=1 check. This is pre-existing (not introduced by this PR) but worth filing as a follow-up issue given the broader minLength audit this PR started.

Similarly, publisher uses if (!metadata.publisher) which lets " " through. In practice NEMAR always sets the publisher to the full institutional name so this is low-risk, but the pattern is inconsistent with the filtering applied to other fields.


Nice-to-haves (1)

6. trim() is sufficient for the failing scenarios but does not strip zero-width spaces or BOM

Zero-width spaces (​), non-breaking spaces ( ), and BOM () pass .trim() and are truthy, so a funder name consisting solely of these characters would pass all guards and be emitted as a near-empty element that could still trip EZID's minLength validator. In practice BIDS datasets are unlikely to contain these characters, but if the EZID rejection rate shows exotic whitespace in the future, a /^\s+$/u regex-based check (which catches Unicode whitespace) or name.trim().replace(/\p{Z}/gu, '') would be more robust. Not blocking.


False positives (0)

None of the findings are false positives. All relate to observable gaps.


Verdict

Mergeable after addressing finding #1 (awardNumber/awardTitle whitespace trim). Finding #2 (uploaderName trim) is a minor inconsistency worth fixing in the same pass. Findings #3–#6 are informational or nice-to-haves; they do not block merge.

Apply trim-and-length guards to awardNumber and awardTitle in
buildDataCiteXml so whitespace-only values are suppressed. Also trim
uploaderName before pushing to contributors so surrounding whitespace
does not appear in emitted XML.

Adds tests for whitespace-only awardNumber/awardTitle suppressed,
padded values emitted trimmed, and padded uploaderName emitted trimmed.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings addressed (commit a31c196)

Finding 1: awardNumber/awardTitle whitespace-only values

Changed if (fund.awardNumber) and if (fund.awardTitle) in buildDataCiteXml to use typeof ... === "string" && ...trim().length > 0 guards. Also trim the values before writing to XML. Whitespace-only strings (e.g. " ", " \t ") no longer emit elements that would fail DataCite's minLength=1 constraint.

Finding 2: uploaderName pushed untrimmed

Extracted trimmedUploaderName = enrichment.uploaderName.trim() and pushed that to the contributor name (the guard already called .trim() but the value written was the raw string). Padded names like " yahya " now emit as yahya in XML.

Tests added (3 new):

  • omits awardNumber and awardTitle from XML when whitespace-only
  • trims awardNumber and awardTitle in XML output
  • DataCurator name is trimmed when uploaderName has surrounding whitespace

All 131 tests pass.

@neuromechanist
neuromechanist merged commit 0ee799f into dev May 14, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-459-datacite-empty-fields branch May 14, 2026 05:14

This branch was previously deployed

1 inactive deployment
npm — a31c196b Deployed May 14, 2026 by neuromechanist via publish #808
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant