Repository navigation
Merge branch '11.x' into master - #1975
Merged
Merged
Conversation
Before loading rows, the msnodesqlv8 driver looks the table up through msnodesqlv8's table manager (after creating it, when create is set). The table manager reports a failed lookup, such as a table in a database that does not exist, as (null, err) rather than error first, and the error was ignored. The callback then threw reading the columns of a null manager, so bulk() never settled, the borrowed connection was never released, and the TypeError surfaced as an unhandled rejection. The lookup error now goes back through the same path as any other bulk failure, which releases the connection and rejects with a RequestError (code EREQUEST). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 8d80e84)
On a connection that uses TDS 7.1, tedious does not send the transaction name as data. It builds it into a `BEGIN TRAN <name>` SQL batch, so a name holding whitespace, `;`, `:` or a comment ended the statement and the rest of it ran as SQL. Even a lone keyword such as `commit` ran as a statement of its own. That applied whether `options.tdsVersion` was set to `7_1` or the server supported nothing newer, because tedious adopts the version the server agrees at login. The name is now read once and, when the connection's TDS version is below 7.2, sent as a quoted identifier with any `]` doubled, so the server stores exactly the name given. From TDS 7.2 the name is sent as before. A name that is not a string is rejected with EINJECT before a connection is taken, and `null` or `undefined` means no name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SQL Server refuses a transaction name longer than 32 UTF-16 code units, and tedious throws on one of 128 or more. begin() still took a pooled connection first, so the failure came from the server or the driver, and on lines without the failed-begin release a name of that length kept the connection out of the pool for good. begin() with the tedious driver now rejects such a name with EINJECT before a connection is taken. A name of 32 code units or fewer is sent as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the msnodesqlv8 driver, a bulk load finds its table through the driver's table manager. The table manager writes the table name into the text of a query of its own, then writes an INSERT from what it found. Neither is quoted in a way that a name cannot end. So a table, schema or database name could end the quoting it was written into, and the rest of the name ran as SQL. The same was true of a column name, or a table name as the server reported it, in the INSERT. The name is now read once, without its brackets as before, and checked before a connection is taken. The table manager is given the string that was checked: - The table and schema names must not hold a single `'`, because they are written into quoted strings. A doubled `''` is still accepted. - The database name must be made of identifier characters. Space around it, or double quotes, are allowed. It must not hold a `'`. - Every part of a temporary table name must be made of identifier characters, because it is written unquoted into the INSERT. - No part may hold a `$` followed by a backtick, a `'` or a `&`. The table manager replaces each of these pairs with a part of its own query, so such a name never named the table it seemed to. When the table manager has found the table, the names it will write are checked too. The name of a table in tempdb is written unquoted into the INSERT, so each of its parts must pass the rule for the database name. This applies also when the name does not say tempdb. A table or a writable column whose name, as the server reports it, holds a `]` is rejected, because the driver writes it in brackets without doubling the `]`. A rejection at this point releases the connection. A rejected name raises EINJECT. A name that passes the checks reaches the table manager unchanged. The tedious driver is not changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`create table` takes a table's path as it is, with either driver, and the tedious driver also writes it into `insert bulk`. A table built from a name always has a path with each part in brackets, but `path` is a plain property, so a path changed after the table was built reached the statement unchecked. The same was true of the table name that `declare()` writes into the name of a composite primary key constraint. The path is now checked as a qualified name where it is written, and before a connection is taken: each part must be bare, or in brackets or double quotes. A `]` in the constraint name must be doubled. Each value is read once, so the value checked is the value written. A path or name that fails raises EINJECT. The existence check that `create` runs first looks the table up by the path as a string. The paths and names that `new sql.Table()` builds are written as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A parameter's type, and the type of each column of a table that a bulk load creates, are declared from the type's `declaration`. Every type in sql.TYPES has a declaration of one word, but any other object passed as a type wrote its own declaration into the statement unchecked. That declaration is now checked by the same rule as the name of a table type: bare, or in brackets or double quotes, optionally with a schema. It may end with a size in parentheses, one or two numbers or `max`. It is read once, so the value checked is the value written. A declaration that fails raises EINJECT. Every type in sql.TYPES is declared as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the tedious driver, a bulk load hands each column's type to tedious, which calls the type's declaration() when it writes the `insert bulk` statement. A type that is neither one of sql.TYPES nor a tedious type made tedious throw there, after a connection had been taken. When the table was created first, it threw in a callback that nothing caught, which ended the process. Such a column type is now refused before a connection is taken, and again where tedious is given it, in case it changed. The bulk load rejects with a RequestError. Every type in sql.TYPES is loaded as before, and so is a tedious type given directly when the table is not created first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # README.md # lib/msnodesqlv8/request.js # lib/tedious/transaction.js # test/common/tests.js # test/common/unit.js # test/tedious/tedious.js
From tedious 20.4.1, a bulk load value that fails validation is reported as "Column '<name>' could not be validated at row index <n>", with the validation error itself as the cause. The test expected the validation error's own message, so it failed in the CI step that installs the latest tedious 20. The test now checks the cause when there is one, so it passes with tedious 19 and every tedious 20 release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🎉 This PR is included in version 12.8.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does:
Merges
11.xintomaster, so thatmastergets the fixes just released on the maintenance lines as 9.1.5, 9.2.3, 9.3.4, 10.0.6 and 11.0.3. These are security fixes, for GHSA-9xm7-qv53-r8cc and GHSA-9ccf-8hhx-4q2w.mastersince 12.7.5, so this one changes nothing here)It also carries one test-only fix that
master's CI needs: from tedious 20.4.1, a bulk load value that fails validation is reported asColumn '<name>' could not be validated at row index <n>, with the validation error as its cause, so the test for a non-string value in a string column now checks the cause when there is one. This fails onmasterwithout this PR too, in the step that installs the latest tedious 20.The merge commit reconciles these with
master's newer code: the transaction begin error handling, the msnodesqlv8 bulk load changes, and unit test fakes of tedious connections, which now carry the TDS version that a real connection always has.Related issues:
Pre/Post merge checklist:
CHANGELOG.txtis not maintained, and semantic-release writes the release notes from the commit subjects)🤖 Generated with Claude Code