-
-
Notifications
You must be signed in to change notification settings - Fork 498
patch 1.4.20 #1637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
patch 1.4.20 #1637
Changes from all commits
5e8822e
4c51409
038d1b3
875d191
42d6eec
ec61f11
ee8b2bf
2528880
0ba69d9
cf79a9d
443eef2
127bc93
7337ba7
5ffb7e6
87c7836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,14 @@ | ||||||||||
| import { Elysia } from '../src' | ||||||||||
| import { Elysia, t } from '../src' | ||||||||||
| import { z } from 'zod' | ||||||||||
| import { req } from '../test/utils' | ||||||||||
|
Comment on lines
+1
to
+3
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused imports. The imports 🔎 Proposed fix-import { Elysia, t } from '../src'
-import { z } from 'zod'
-import { req } from '../test/utils'
+import { Elysia } from '../src'📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| // This uses aot: true by default in 1.4 (broken on Bun) | ||||||||||
| const app = new Elysia({ systemRouter: true }) | ||||||||||
| .get("/", "Hello Elysia") | ||||||||||
| .get("/json", () => ({ message: "Hello World", timestamp: Date.now() })) | ||||||||||
|
|
||||||||||
| Bun.serve({ | ||||||||||
| port: 3000, | ||||||||||
| fetch: app.fetch | ||||||||||
| }) | ||||||||||
| export const app = new Elysia() | ||||||||||
| .ws('/', { | ||||||||||
| open(ws) { | ||||||||||
| ws.subscribe('a') | ||||||||||
| }, | ||||||||||
| message(a) { | ||||||||||
| console.log(a.subscriptions) | ||||||||||
| } | ||||||||||
| }) | ||||||||||
| .listen(3000) | ||||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ import { | |||
|
|
||||
| import { t, type TypeCheck } from './type-system' | ||||
|
|
||||
| import { deepClone, mergeCookie, mergeDeep, randomId } from './utils' | ||||
| import { mergeCookie, mergeDeep, randomId } from './utils' | ||||
| import { mapValueError } from './error' | ||||
|
|
||||
| import type { CookieOptions } from './cookies' | ||||
|
|
@@ -28,11 +28,15 @@ import type { | |||
| MaybeArray, | ||||
| StandaloneInputSchema, | ||||
| StandardSchemaV1LikeValidate, | ||||
| UnwrapSchema | ||||
| UnwrapSchema | ||||
| } from './types' | ||||
|
|
||||
| import type { StandardSchemaV1Like } from './types' | ||||
| import { replaceSchemaTypeFromManyOptions, type ReplaceSchemaTypeOptions, stringToStructureCoercions } from './replace-schema' | ||||
| import { | ||||
| replaceSchemaTypeFromManyOptions, | ||||
| type ReplaceSchemaTypeOptions, | ||||
| stringToStructureCoercions | ||||
| } from './replace-schema' | ||||
|
|
||||
| type MapValueError = ReturnType<typeof mapValueError> | ||||
|
|
||||
|
|
@@ -127,12 +131,12 @@ export const hasAdditionalProperties = ( | |||
| /** | ||||
| * Resolve a schema that might be a model reference (string) to the actual schema | ||||
| */ | ||||
| export const resolveSchema = ( | ||||
| export const resolveSchema = ( | ||||
| schema: TAnySchema | string | undefined, | ||||
| models?: Record<string, TAnySchema | StandardSchemaV1Like>, | ||||
| modules?: TModule<any, any> | ||||
| ): TAnySchema | StandardSchemaV1Like | undefined => { | ||||
| if (!schema) return undefined | ||||
| ): TAnySchema | StandardSchemaV1Like | undefined => { | ||||
| if (!schema) return undefined | ||||
| if (typeof schema !== 'string') return schema | ||||
|
|
||||
| // Check modules first (higher priority) | ||||
|
|
@@ -143,7 +147,7 @@ export const hasAdditionalProperties = ( | |||
|
|
||||
| // Then check models | ||||
| return models?.[schema] | ||||
| } | ||||
| } | ||||
|
|
||||
| export const hasType = (type: string, schema: TAnySchema): boolean => { | ||||
| if (!schema) return false | ||||
|
|
@@ -165,7 +169,11 @@ export const hasType = (type: string, schema: TAnySchema): boolean => { | |||
| if (schema.allOf) return schema.allOf.some((s: TSchema) => hasType(type, s)) | ||||
|
|
||||
| if (schema.type === 'array' && schema.items) { | ||||
| if (type === 'Files' && Kind in schema.items && schema.items[Kind] === 'File') { | ||||
| if ( | ||||
| type === 'Files' && | ||||
| Kind in schema.items && | ||||
| schema.items[Kind] === 'File' | ||||
| ) { | ||||
| return true | ||||
| } | ||||
| return hasType(type, schema.items) | ||||
|
|
@@ -459,18 +467,20 @@ export const getSchemaValidator = < | |||
| if (!schema) return undefined as any | ||||
| } | ||||
|
|
||||
| const hasAdditionalCoerce = Array.isArray(additionalCoerce) ? | ||||
| additionalCoerce.length > 0 : !!additionalCoerce | ||||
| const hasAdditionalCoerce = Array.isArray(additionalCoerce) | ||||
| ? additionalCoerce.length > 0 | ||||
| : !!additionalCoerce | ||||
|
|
||||
| if (Kind in schema) { | ||||
| if (schema[Kind] === 'Import') { | ||||
| if (!hasRef(schema.$defs[schema.$ref])) { | ||||
| schema = schema.$defs[schema.$ref] | ||||
| schema = schema.$defs[schema.$ref] ?? models[schema.$ref] | ||||
|
|
||||
| if (coerce || hasAdditionalCoerce) { | ||||
| schema = replaceSchema(schema as TSchema) | ||||
| if ('$id' in schema && !schema.$defs) { | ||||
| schema.$id = `${schema.$id}_coerced_${randomId()}`; | ||||
| } | ||||
|
|
||||
| if ('$id' in schema && !schema.$defs) | ||||
| schema.$id = `${schema.$id}_coerced_${randomId()}` | ||||
| } | ||||
|
Comment on lines
+477
to
484
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for other locations where schema.$ref and schema.$defs are accessed together
rg -n -C3 '\$defs\[\s*schema\.\$ref\s*\]' src/Repository: elysiajs/elysia Length of output: 1750 🏁 Script executed: #!/bin/bash
# Read the context around lines 476-483 in src/schema.ts
sed -n '460,500p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 1377 🏁 Script executed: #!/bin/bash
# Find the hasRef function definition
rg -n 'const hasRef|function hasRef|export const hasRef' src/Repository: elysiajs/elysia Length of output: 133 🏁 Script executed: #!/bin/bash
# Get more context around line 475 to understand the logic flow
sed -n '470,490p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 783 🏁 Script executed: #!/bin/bash
# Check the unwrapImportSchema function at lines 1351-1356
sed -n '1351,1360p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 292 🏁 Script executed: #!/bin/bash
# Get the full hasRef function definition
sed -n '285,310p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 1032 🏁 Script executed: #!/bin/bash
# Search for where Import schemas are created to understand their structure
rg -n "Kind.*===.*'Import'" src/ -A 3 | head -50Repository: elysiajs/elysia Length of output: 1645 🏁 Script executed: #!/bin/bash
# Search for usages of unwrapImportSchema
rg -n 'unwrapImportSchema' src/Repository: elysiajs/elysia Length of output: 634 🏁 Script executed: #!/bin/bash
# Also check the context to understand when Import schemas are created
# and if schema.$defs[schema.$ref] can ever be undefined
sed -n '158,165p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 338 🏁 Script executed: #!/bin/bash
# Check how unwrapImportSchema is used in compose.ts to see if there's protection
sed -n '715,725p' src/compose.ts | cat -nRepository: elysiajs/elysia Length of output: 551 🏁 Script executed: #!/bin/bash
# Check the context of another unwrapImportSchema usage
sed -n '1355,1370p' src/compose.ts | cat -nRepository: elysiajs/elysia Length of output: 583 🏁 Script executed: #!/bin/bash
# Verify if the Import schema is guaranteed to have schema.$defs[schema.$ref]
# by checking how Import schemas are created
rg -n "t\.Import|Kind.*Import" src/schema.ts | grep -E "export|function" | head -10Repository: elysiajs/elysia Length of output: 41 🏁 Script executed: #!/bin/bash
# Check if hasRef function can handle undefined input
sed -n '285,295p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 444 🏁 Script executed: #!/bin/bash
# Check the critical line 475 - does hasRef protect against undefined?
# and verify if schema.$defs[schema.$ref] could be undefined at this point
rg -n "if.*hasRef\(schema\.\$defs" src/schema.ts -A 2 -B 2Repository: elysiajs/elysia Length of output: 41 🏁 Script executed: #!/bin/bash
# Verify the actual potential issue - what happens if schema.$defs is undefined
# when we call hasRef(schema.$defs[schema.$ref])?
python3 << 'EOF'
# Simulate what happens at line 475
schema_defs = None # or could be undefined
schema_ref = "someRef"
# This is what line 475 does:
try:
result = schema_defs[schema_ref]
print(f"Result: {result}")
except TypeError as e:
print(f"ERROR at line 475: {e} - trying to access undefined schema.$defs")
EOFRepository: elysiajs/elysia Length of output: 145 🏁 Script executed: #!/bin/bash
# Look at the exact context around line 475 with more lines
sed -n '473,478p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 312 🏁 Script executed: #!/bin/bash
# Check if schema.$defs is guaranteed to exist before line 475
# by looking at how Import schemas are created
rg -n 'Kind.*Import' src/schema.ts -B 5 | head -40Repository: elysiajs/elysia Length of output: 1255 🏁 Script executed: #!/bin/bash
# Check if there are any Import schemas created without $defs
rg -n "schema\.\[Kind\]\s*=\s*'Import'" src/ -A 5 | head -50Repository: elysiajs/elysia Length of output: 41 🏁 Script executed: #!/bin/bash
# Look at the full context - is schema.$defs guaranteed to exist?
# Check what happens before line 475
sed -n '440,478p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 1377 🏁 Script executed: #!/bin/bash
# Check if Import schemas are always created with $defs
# by looking at the t.Import or Module creation
rg -n "\.Import\(" src/ -B 3 -A 3 | head -60Repository: elysiajs/elysia Length of output: 1688 🏁 Script executed: #!/bin/bash
# Check dynamic-handle.ts to see how it safely handles this
sed -n '30,40p' src/dynamic-handle.ts | cat -nRepository: elysiajs/elysia Length of output: 438 🏁 Script executed: #!/bin/bash
# Check if there's a potential issue at line 475 with direct access
# Is schema.$defs always defined for Import schemas?
# Let's look for where schema.$defs could be undefined
rg -n "Kind.*===.*'Import'" src/schema.ts -A 5 | grep -E "(\$defs|schema\.\[)" | head -20Repository: elysiajs/elysia Length of output: 41 🏁 Script executed: #!/bin/bash
# Check the actual issue - line 475 does direct access without checking $defs exists
# while line 476 has a fallback. Is this inconsistent?
sed -n '473,483p' src/schema.tsRepository: elysiajs/elysia Length of output: 428 🏁 Script executed: #!/bin/bash
# Verify if unwrapImportSchema at line 1354 has the same vulnerability
sed -n '1351,1360p' src/schema.tsRepository: elysiajs/elysia Length of output: 250 🏁 Script executed: #!/bin/bash
# Let me verify - is line 475 accessing schema.$defs without safety check?
# This could be a critical issue
sed -n '474,477p' src/schema.ts | cat -nRepository: elysiajs/elysia Length of output: 232 🏁 Script executed: #!/bin/bash
# Check if hasRef handles undefined gracefully
sed -n '285,290p' src/schema.tsRepository: elysiajs/elysia Length of output: 254 🏁 Script executed: #!/bin/bash
# Double-check: what happens if schema.$defs is undefined at line 475?
# Line 475: if (!hasRef(schema.$defs[schema.$ref]))
# This will throw TypeError if schema.$defs is undefined
rg -n "if.*!hasRef.*\\\$defs" src/schema.tsRepository: elysiajs/elysia Length of output: 108 Critical: Line 475 still has unsafe direct access to The added fallback Both lines 475 and 476 need optional chaining for safety: Additionally, The condition at line 481 ( |
||||
| } | ||||
| } else { | ||||
|
|
@@ -493,6 +503,7 @@ export const getSchemaValidator = < | |||
| } | ||||
|
|
||||
| let schema = mapSchema(s) | ||||
| // console.log([s, schema]) | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Remove debug console.log before merging. This commented-out debug statement should be removed to keep the codebase clean. 🔎 Proposed fix- // console.log([s, schema])📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| let _validators = validators | ||||
|
|
||||
| if ( | ||||
|
|
@@ -696,19 +707,19 @@ export const getSchemaValidator = < | |||
| ) | ||||
| schema.additionalProperties = additionalProperties | ||||
| else | ||||
| schema = replaceSchemaTypeFromManyOptions(schema, { | ||||
| onlyFirst: "object", | ||||
| from: t.Object({}), | ||||
| to(schema) { | ||||
| if (!schema.properties) return schema; | ||||
| if ("additionalProperties" in schema) return schema; | ||||
|
|
||||
| return t.Object(schema.properties, { | ||||
| ...schema, | ||||
| additionalProperties: false, | ||||
| }); | ||||
| } | ||||
| }); | ||||
| schema = replaceSchemaTypeFromManyOptions(schema, { | ||||
| onlyFirst: 'object', | ||||
| from: t.Object({}), | ||||
| to(schema) { | ||||
| if (!schema.properties) return schema | ||||
| if ('additionalProperties' in schema) return schema | ||||
|
|
||||
| return t.Object(schema.properties, { | ||||
| ...schema, | ||||
| additionalProperties: false | ||||
| }) | ||||
| } | ||||
| }) | ||||
| } | ||||
|
|
||||
| if (dynamic) { | ||||
|
|
@@ -1098,7 +1109,10 @@ export const mergeObjectSchemas = ( | |||
| ...newSchema.properties, | ||||
| ...schema.properties | ||||
| }, | ||||
| required: [...(newSchema?.required ?? []), ...(schema.required ?? [])] | ||||
| required: [ | ||||
| ...(newSchema?.required ?? []), | ||||
| ...(schema.required ?? []) | ||||
| ] | ||||
| } as TObject | ||||
| } | ||||
|
|
||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidate duplicate "Bug fix:" header and add missing issue reference.
Lines 7-15 contain two separate "Bug fix:" headers, which breaks the standard changelog format used throughout the file. Additionally, the last item on line 15 lacks an issue/PR reference that all other entries include.
Merge the two sections into a single "Bug fix:" header and add a reference to the non-typebox model issue.
🔎 Proposed fix
Note: If the last item references a specific issue/PR, include its number in the format
[#XXXX](link)before the description.📝 Committable suggestion
🤖 Prompt for AI Agents