Skip to content

What's the purpose of the options.sameSite branch of ternary in serialize? #206

Description

@jonchurch

What's the purpose of the options.sameSite branch of ternary in serialize?

When options.priority is not a string, it will use options.sameSite. There's no overlap in the types between the two, so we'd hit the default and throw. Was there meant to be overlap or is this a typo?

: options.sameSite;

  if (options.priority) {
    const priority =
      typeof options.priority === "string"
        ? options.priority.toLowerCase()
        : options.sameSite; // typo?
    switch (priority) {
      case "low":
        str += "; Priority=Low";
        break;
      case "medium":
        str += "; Priority=Medium";
        break;
      case "high":
        str += "; Priority=High";
        break;
      default:
        throw new TypeError(`option priority is invalid: ${options.priority}`);
    }
  }

Activity

  1. jonchurch commented on Nov 15, 2024

    @jonchurch
    MemberAuthor

    It's functionally sound, non strings will throw with the correct error, except in the edgecase where someone did {priority: 1, sameSite: "low"}

    That still throws, but only once we validate options.sameSite

  2. blakeembrey commented on Nov 15, 2024

    @blakeembrey
    Member

    In the old code it was for the error message, this was a bad copy and paste when I re-added case insensitivity:

    cookie/index.js

    Lines 254 to 269 in e206fd5

    var priority = typeof opt.priority === 'string'
    ? opt.priority.toLowerCase() : opt.priority;
    switch (priority) {
    case 'low':
    str += '; Priority=Low'
    break
    case 'medium':
    str += '; Priority=Medium'
    break
    case 'high':
    str += '; Priority=High'
    break
    default:
    throw new TypeError('option priority is invalid: ' + priority)
    }

    Honestly, throwing options.priority instead of priority is a bit nicer and should not have tried to copy the same fallback behavior in the previous code.

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