Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 161 additions & 106 deletions dist/jquery.form.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.form.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.form.min.js.map

Large diffs are not rendered by default.

267 changes: 161 additions & 106 deletions dist/jquery.form.mjs

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions docs/metrics.md

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion docs/plans/modernization.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ content: "Coverage to 100%: remove dead and over-defensive branches, refactor fo
status: pending
- id: security-fixes
content: "Security and bug fixes: private advisories, review findings, P1 and Phase 5 it.fails bugs"
status: pending
status: in_progress
- id: cleanup-4x
content: "4.x cleanup and rearchitecture without breaking changes: source modules, lower complexity, additive options, deprecations"
status: pending
Expand Down Expand Up @@ -298,6 +298,15 @@ enforces it. Each removed branch and the reason it was dead are in `docs/researc
- The P1 bugs #588, #597, #600 and #553, and the remaining Phase 5 `it.fails` records: label lookup, iframe parsererror overwrite, double completion and pending Deferred on abort.
- Each `it.fails` becomes an `it`, and coverage stays at 100%.

Status: the public fixes are on `phase-10-fixes`. They cover findings 4, 6, 7 and 8, #588, #600 and #553, and the
iframe parsererror, double-completion and abort records. Coverage stays at 100%.

- The label record and #597 land with W1–W4 on release day.
- Decisions: an aborted upload also fires `ajaxComplete` and `ajaxStop`, and the `clk` expandos stay
on the form until 5.x.
- `npm audit` now reports 6 moderate advisories in dev dependencies only (`minimatch` via ESLint,
GHSA-g3hv-75wg-m249); the runtime dependency has none.

## Phase 11: 4.x cleanup and rearchitecture (no breaking change)

- Split `src/jquery.form.js` into source modules: serialization, field helpers, XHR transport, iframe transport, `ajaxForm` binding. Rollup emits the same `dist` files, and the surface tests prove ADR-0001 still holds.
Expand Down
13 changes: 13 additions & 0 deletions docs/research/4x-behavior-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ Collected as the modernization proceeds. Each entry is a change a consumer could

- **Iframe uploads with `dataType: "script"` now run the response.** The iframe transport returned the script text without evaluating it; it now evaluates it with `$.globalEval`, as `$.ajax` does. Only an explicit `dataType: "script"` does this. Other data types are unchanged.

## Phase 10

- **A `<button>` without a `type` attribute is captured as the submitter (#588).** Its name and value are sent, as in a native submit. Clicks on other elements that only carry a `type="submit"` attribute, and on submit controls that belong to no form, are ignored instead of throwing.
- **`resetForm`, `clearFields`, `fieldValue` and `selected` accept nodes without a tag name (#600).** `resetForm` on the document resets the fields inside it. Text nodes are skipped.
- **The Rails CSRF token is added only to same-origin iframe uploads.** An upload whose `url` or action points to another origin no longer receives the `<meta name="csrf-token">` value. `jquery-ujs` behaves the same way.
- **An aborted iframe upload rejects its Deferred and finishes its global events.** `abort()` rejects the returned jqXHR with `(xhr, "aborted", status)`, fires `ajaxComplete` and `ajaxStop`, decrements `$.active` and removes the iframe. Timeouts and server aborts do the same, and their rejection arguments are unchanged. A second `abort()`, an abort after the upload completed, or one from the `success` callback does nothing. An abort while the response is processed (for example from `dataFilter`) completes the upload once.
- **Iframe responses that fail to parse report `parsererror`.** An emulated 2xx status (the `status` attribute on the response body or textarea) used to turn a parse error into `success` with no data. An emulated error status still reports `error`.
- **FormData uploads serialize `data` with the global `$.ajaxSettings.traditional`,** as the other transports already did. `data: {}` no longer adds a field with an empty name.
- **GET urls keep the form data when the `url` option has a fragment.** The query now goes before the fragment; jQuery used to drop it with the fragment. An action that is only a fragment, read raw because a control is named `action`, now submits to the current page instead of throwing on GET or posting to `undefined`.
- **Controls named like form members no longer break serialization or uploads.** A control named `elements` no longer hides the other fields from `formToArray`. Controls named `setAttribute` or `removeAttribute` no longer break the iframe transport, except on jQuery 1.7.2, whose selector engine fails on them first. After an iframe upload, a form with a control named `action` and no `action` attribute keeps having none.
- **An extra field named `hasOwnProperty` no longer breaks iframe uploads,** whether it comes from `data`, `extraData` or the submit button's name.
- **`dist/` files no longer contain `/* eslint */` or `/* global */` comments (#553),** which applied to code concatenated after the plugin.

## Known behavior, not changed

- **`dataType: "script"` on jQuery 4** delivers `undefined` to `success`; jQuery 4 loads async script requests through a script tag. The script still runs. This comes from jQuery, not the plugin.
Expand Down
6 changes: 6 additions & 0 deletions docs/research/coverage-findings.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
it to `success` for a 2xx response.
- Test treatment: `it.fails`; its exercised source lines still count toward coverage.
- Suggested fix: only derive success/error from `xhr.status` when response parsing has not failed.
- Fixed in Phase 10: an emulated error status still reports `error`, but a 2xx status keeps the
parse error, and the test is an `it`.

## Aborting an iframe upload while its response is processed completes twice

Expand All @@ -48,6 +50,8 @@
- Test treatment: `it.fails`; its exercised source lines still count toward coverage.
- Suggested fix: return from `cb` after the `xhr.aborted` check instead of continuing with a null
status.
- Fixed in Phase 10: `cb` returns after an abort, abort is ignored once the upload has completed,
and the test is an `it`.

## Aborting an iframe upload leaves its Deferred pending

Expand All @@ -57,3 +61,5 @@
- Test treatment: `it.fails`; its exercised source lines still count toward coverage.
- Suggested fix: reject the Deferred exactly once from the abort path with the same arguments used by
the timeout and server-abort paths.
- Fixed in Phase 10: abort rejects the Deferred once and also fires `ajaxComplete` and `ajaxStop`,
which the abort and timeout paths used to skip. The test is an `it`.
2 changes: 2 additions & 0 deletions docs/research/issue-triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jQuery 1.7.2, 3.7.1 and 4.0.0.
| #600 | `clearForm should skip nodes without a tag name` (`clearFields`) | `TypeError` reading `toLowerCase` of `undefined` |
| #553 | `dist files should not ship file-wide ESLint configuration comments` (surfaces) | `/* eslint consistent-this … */` found in both builds |

Phase 10 fixed #588, #600 and #553; their tests are now `it`.

Not reproduced: #541 (needs a slim-build test harness; deferred with the 5.0 item), #525 (EdgeHTML upload progress; that browser is retired), #548 is #353 (already an
`it.fails`), #590 is server-side naming (see below).

Expand Down
10 changes: 6 additions & 4 deletions docs/research/security-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Ranked by severity, then by who controls the input.
| 1 | `target` inserts the response as HTML and runs its scripts | Server response | All | Medium | Phase 11 (opt-in) |
| 2 | `delegation: true` takes over every form on the page | Page | ≥ 3.0 | Medium | Phase 11, Phase 12 |
| 3 | The iframe transport renders the response as a same-origin document | Server response | All | Medium | Docs, Phase 12 |
| 4 | The Rails CSRF token is sent to cross-origin upload URLs | Page, developer | All | Medium | Phase 10 |
| 4 | The Rails CSRF token is sent to cross-origin upload URLs | Page, developer | All | Medium | Phase 10 (fixed) |
| 5 | The supported jQuery range includes versions with CVEs the plugin reaches | Consumer | < 3.5 | Medium | Docs, Phase 12 |
| 6 | Form fields named like form properties break serialization and uploads | DOM text | All | Low | Phase 10 |
| 7 | `hasOwnProperty` is called as a method on `extraData` | Developer | All | Low | Phase 10 |
| 8 | Robustness: crashes and lost data on unusual input | DOM text, developer | Varies | Low | Phase 10 |
| 6 | Form fields named like form properties break serialization and uploads | DOM text | All | Low | Phase 10 (fixed) |
| 7 | `hasOwnProperty` is called as a method on `extraData` | Developer | All | Low | Phase 10 (fixed) |
| 8 | Robustness: crashes and lost data on unusual input | DOM text, developer | Varies | Low | Phase 10 (fixed) |
| 9 | #554 "code injection" is a false positive | — | — | Info | Close #554 |
| 10 | `semantic: true` collects every named element, not only form controls | DOM text | All | Info | Phase 12 |
| 11 | Options that are URLs or selectors must be trusted | Developer | All | Info | Docs |
Expand Down Expand Up @@ -117,6 +117,8 @@ HTML lets a control's `name` shadow the form's own properties and methods. Confi

Fix: call `HTMLFormElement.prototype` methods and read `elements` through them, and keep the click state in `$.data` instead of on the form.

Phase 10 fixed `elements` and the iframe transport's attribute writes. The `clk` expandos stay on the form in 4.x, because consumers and the suite read and set them; 5.x replaces them with `SubmitEvent.submitter`.

### 7. `hasOwnProperty` on `extraData`

Line 669 calls `s.extraData.hasOwnProperty(n)`, and lines 673–674 make the same call on each value. An extra field named `hasOwnProperty` (for example a `data` key) replaces the method. The iframe upload then throws a `TypeError` (confirmed on all three versions).
Expand Down
3 changes: 1 addition & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const sourceRules = {
"arrow-body-style": "error",
"class-methods-use-this": "error",
"consistent-return": "error",
"consistent-this": ["error", "that", "outerThis", "self"],
"consistent-this": ["error", "$form", "that", "outerThis", "self"],
"default-case": "error",
"dot-notation": "error",
eqeqeq: "error",
Expand Down Expand Up @@ -75,7 +75,6 @@ const sourceRules = {
"sort-imports": "error",
yoda: "error",
"no-unused-vars": ["error", { vars: "local", args: "none", caughtErrors: "none" }],
"no-prototype-builtins": "warn",
};

export default [
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const umdHeader = `(function (factory) {

const moduleLines =
/^import jQuery from ['"]jquery['"];\nexport \{ default \} from ['"]jquery['"];\n\n/;
const preamble = /^\/\*![\s\S]*?\*\/\n\/\* global ActiveXObject \*\/\n\n?/m;
const preamble = /^\/\*![\s\S]*?\*\/\n\n?/m;
const bodyStart = "(function ($) {\n";

// Rollup places the license preamble after the imports; lift it back to the top of the file.
Expand Down
Loading
Loading