client.api() throws "Unable to parse the URL" for relative paths containing https:// in the query

Aperta Adatta ai principianti
#2,039 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@pcbeingused333 ci sta già lavorando.

Dal 16/11/2026.

  • #2040 di @pcbeingused333 — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js, typescript
Ambito
api

Direzione di ricerca

Inizia da parsePath in src/GraphRequest.ts intorno alla riga 134, dove il controllo dell’URL assoluto usa path.indexOf("https://") prima di chiamare new URL(path); esegui lo script di repro dell’issue contro una build locale per vedere i tre errori. Cambia il test in un controllo startsWith senza distinzione tra maiuscole e minuscole, così solo i percorsi assoluti genuini prendono quel ramo, e mantieni il ramo relativo che si risolve rispetto all’URL di base configurato più la versione. Il risultato finale è che tutti e tre i percorsi di repro stampano gli URL attesi https://graph.microsoft.com/v1.0/... mentre i percorsi completi https://graph.microsoft.com/... vengono ancora analizzati, più un test di regressione nella suite GraphRequest esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

client.api(path) throws Error: Unable to parse the URL: ... (GraphClientError) when given a relative path whose query string or OData function parameter contains https://, such as /sites?search=https://contoso.sharepoint.com or /me/events?$filter=onlineMeeting/joinUrl eq 'https://...'.

In 3.0.7, the same calls did not throw, but stripped https:// from the query and built a broken URL (https:/v1.0/sites?search=contoso.sharepoint.com).

Expected behavior

Relative paths should resolve against the configured base URL and version (https://graph.microsoft.com/v1.0/sites?search=https://contoso.sharepoint.com, etc.), matching the behavior of .query() and .filter() for the same values.

How to reproduce
npm install @microsoft/[email protected]
node repro.js

repro.js:

const { Client } = require("@microsoft/microsoft-graph-client");
const client = Client.init({ authProvider: (done) => done(null, "token") });

for (const path of [
  "/sites?search=https://contoso.sharepoint.com",
  "/me/events?$filter=onlineMeeting/joinUrl eq 'https://teams.microsoft.com/l/x'",
  "/me/drive/root/search(q='https://example')",
]) {
  try {
    console.log(client.api(path).buildFullUrl());
  } catch (e) {
    console.log(e.message);
  }
}

Actual output (3.1.0):

Unable to parse the URL: /sites?search=https://contoso.sharepoint.com
Unable to parse the URL: /me/events?$filter=onlineMeeting/joinUrl eq 'https://teams.microsoft.com/l/x'
Unable to parse the URL: /me/drive/root/search(q='https://example')
SDK Version

3.1.0 (also on dev 4434ef722 and main ba4103712)

Latest version known to work for scenario above?

None (3.0.7 returned malformed URLs such as https:/v1.0/sites?search=contoso.sharepoint.com instead of throwing)

Known Workarounds

Pass the parameter through .query() / .filter() instead of inline in api(), or percent-encode :// in the parameter value.

Debug output
Click to expand log
Error: Unable to parse the URL: /sites?search=https://contoso.sharepoint.com
    at new GraphClientError (node_modules/@microsoft/microsoft-graph-client/lib/src/GraphClientError.js:30:28)
    at GraphRequest.parsePath (node_modules/@microsoft/microsoft-graph-client/lib/src/GraphRequest.js:51:27)
    at new GraphRequest (node_modules/@microsoft/microsoft-graph-client/lib/src/GraphRequest.js:105:14)
    at Client.api (node_modules/@microsoft/microsoft-graph-client/lib/src/Client.js:97:16)
Configuration
  • OS: Linux x64
  • Node.js: v26.13.0 (not OS- or runtime-specific)
Other information

GraphRequest.parsePath (src/GraphRequest.ts, line 134) checks if (path.indexOf("https://") !== -1) to decide whether path is an absolute URL, and PR #2000 added new URL(path) inside that branch. Checking whether path starts with https:// (case-insensitively) instead of indexOf would avoid treating query values containing https:// as absolute URLs.

Credit: https://ucsbplse.github.io/

Lingua principale
TypeScript
Stelle
836
Fork
241
Merge medio
1g 12h
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoftgraph/msgraph-sdk-javascript

Tutte le issue di microsoftgraph/msgraph-sdk-javascript

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.