Opening an /index.php/apps/deck/... URL on a pretty-URL instance rewrites it to /apps/deck/index.php/apps/deck/...

Aperta Adatta ai principianti
#8,782 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
frontend

Direzione di ricerca

Inizia da src/router.js intorno al calcolo dell'URL di base (righe 16-23) e confrontalo con la pulizia di /index.php in App.vue mounted(). Per riprodurre, apri /index.php/apps/deck/board/<id>/card/<id> su un'istanza con modRewriteWorking === true e osserva la prima chiamata a routerHistory.replace. Il lavoro è completato quando un URL del genere resta come aperto oppure viene normalizzato in /apps/deck/board/<id>/card/<id>, e la normale navigazione con URL puliti continua a funzionare.

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

Descrizione

Describe the bug

On an instance with pretty URLs enabled (front_controller_active, so OC.config.modRewriteWorking === true), opening a Deck URL that contains /index.php leaves the browser at a doubled path:

https://cloud.example.com/index.php/apps/deck/board/5/card/1589
  → address bar: https://cloud.example.com/apps/deck/index.php/apps/deck/board/5/card/1589

/index.php/... links are common: Nextcloud's server generates them whenever pretty URLs are off, and integrations use them because they work on every instance.

Cause

src/router.js:

const baseUrl = generateUrl('/apps/deck/')
const webRootWithIndexPHP = getRootUrl() + '/index.php'
const doesURLContainIndexPHP = window.location.pathname.startsWith(webRootWithIndexPHP)
const currentBaseUrl = doesURLContainIndexPHP ? baseUrl : baseUrl.replace('/index.php/', '/')

This assumes generateUrl('/apps/deck/') always returns /index.php/apps/deck/. When modRewriteWorking is true it returns /apps/deck/, so a URL that does contain /index.php gets the base /apps/deck/. Then:

  1. vue-router can't strip that base from /index.php/apps/deck/board/5/card/1589, so the route path is the whole pathname.
  2. On the first navigation the router calls routerHistory.replace(fullPath), i.e. replaceState(base + fullPath) = /apps/deck + /index.php/apps/deck/board/5/card/1589.

The cleanup in App.vue mounted() (redirect when $route.path starts with /index.php) doesn't rescue it in practice.

To Reproduce

  1. Use an instance with pretty URLs enabled (htaccess.RewriteBase set, Apache with mod_rewrite).
  2. Open https://<host>/index.php/apps/deck/board/<id>/card/<id> (or /index.php/apps/deck/board/<id>).
  3. The address bar shows https://<host>/apps/deck/index.php/apps/deck/board/<id>/....

Expected behavior

The URL stays as opened, or is normalised to /apps/deck/board/<id>/card/<id>.

Possible fix

Build the base from the current URL rather than from generateUrl():

const webRoot = getRootUrl()
const doesURLContainIndexPHP = window.location.pathname.startsWith(webRoot + '/index.php/')
const currentBaseUrl = webRoot + (doesURLContainIndexPHP ? '/index.php' : '') + '/apps/deck/'

Workaround

/index.php/apps/deck/card/<cardId> (page#redirectToCard) works, because the server redirects with linkToRouteAbsolute(), which drops index.php when pretty URLs are on. Board links have no equivalent redirect route.

Server details

Web server: Apache (official nextcloud Docker image, Helm chart, apache-pretty-urls.config.php enabled)

Nextcloud version: 35.0.3

Deck: current release from the app store. The code above is unchanged on main at 5be5601a.

Lingua principale
JavaScript
Stelle
1.4k
Fork
369
Merge medio
1g 2h
PR unite (30g)
86

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 nextcloud/deck

Tutte le issue di nextcloud/deck

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.