Skip to content

task solve#431

Open
kifont wants to merge 1 commit intomate-academy:masterfrom
kifont:develop
Open

task solve#431
kifont wants to merge 1 commit intomate-academy:masterfrom
kifont:develop

Conversation

@kifont
Copy link
Copy Markdown

@kifont kifont commented Oct 8, 2025

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Decision: APPROVE — The implementation meets the core requirements: it parses the path into parts (ignoring empty segments), parses query parameters into a query object, and responds with valid JSON using standard Node APIs.

Minor, non-blocking notes for robustness and clarity:

  • On src/createServer.js, when calling decodeURIComponent on the entire path, a malformed percent-encoding (e.g., a stray %) can throw and crash the handler. Consider decoding each segment individually (e.g., split by / and map(seg => decodeURIComponent(seg))) or wrapping in try/catch to avoid a crash.
  • When iterating URLSearchParams, duplicate keys (e.g., ?a=1&a=2) overwrite earlier values. If you need to preserve all values, consider params.getAll(key) and storing arrays like { a: ["1", "2"] }.
  • Small cleanup: using res.writeHead(200, { 'Content-Type': 'application/json' }) is preferred over including a reason phrase.

Overall, nicely done—clear, concise, and correct for the task. The suggestions above are optional improvements to handle edge cases more gracefully.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

// Return instance of http.Server class
const server = http.createServer((req, res) => {
const [path, queryString = ''] = req.url.split('?');
const parts = decodeURIComponent((path || '/').slice(1))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You call decodeURIComponent on the entire path string. If the path contains malformed percent-encoding (e.g. a stray %), decodeURIComponent will throw and crash the request handler. The task doesn't require handling malformed encoding, but to be more robust consider decoding each path segment individually instead of the whole path at once, for example:

const parts = (path || '/')
  .slice(1)
  .split('/')
  .filter(Boolean)
  .map(seg => decodeURIComponent(seg));

This avoids an exception caused by one bad segment and still satisfies the requirement to ignore empty segments.

Comment on lines +16 to +17
for (const [key, value] of params) {
query[key] = value;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLSearchParams iteration yields each key/value pair, and the current code sets query[key] = value, which means if the same key appears multiple times (e.g. ?a=1&a=2) the last value wins and earlier ones are overwritten. The task example uses single values, but the description says "all queryParams" — if you must preserve multiple values, consider storing arrays or using params.getAll(key) and produce "a": ["1", "2"]. If single-string values are acceptable, no change is required, but be aware of this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants