duckduckgo / duckduckgo/content-scope-scripts

processAttr: NaN default value silently breaks identity check

Open
#2,268 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
70
Forks
35
Avg merge
2d 19h
Merged PRs (30d)
40

Description

Problem

processAttr(undefined, defaultValue) returns defaultValue via identity (return defaultValue), but if a feature author passes NaN as the default, downstream comparisons like result === expected will always be false because NaN !== NaN in JavaScript.

This was discovered via a property test that generated NaN as a default value. While feature authors don't currently pass NaN, the function has no guard against it.

Options

  1. Document that NaN is not a supported default — cheapest, matches current reality
  2. Normalize NaN to undefined or null — defensive, prevents subtle bugs if a config accidentally produces NaN (e.g. parseInt('abc'))
  3. No change needed — if the type system (ConfigSetting) already prevents this

Context

Found in PR #2261. The property test was narrowed to realistic defaults as a workaround.

// src/utils.js — processAttr
if (configSetting === undefined) {
    return defaultValue; // if defaultValue is NaN, callers can't compare the result
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/utils.js at processAttr and review the property-test context from PR #2261. Decide which behavior should apply when defaultValue is NaN, then update the relevant implementation or documentation and ensure the property test reflects the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.