WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.65k stars 261 forks source link

Fetching a URL that redirects has the first page content prepended #1476

Open akirk opened 5 months ago

akirk commented 5 months ago

I ran into this with Translate Live:

const fetchTranslations = function() {
    const url = '/glotpress/projects/' + localProjectPath + '/' + lang + '/' + translation_set_slug + '/export-translations?format=po&filters[user_login]=admin';
    playground.request( { url } ).then( function( po ) {
        const po_content = new TextDecoder().decode( po.bytes );
    } );
};

That URL is being redirected (which I might be able to get rid of) and it reveals non-standard behavior because the text of the redirecting page is prepended to the content:

Umleitung nach: /scope:0.3732595394027483/glotpress/projects/local-plugins/friends/de/default/export-translations/?format=po&filters[user_login]=admin …# Translation of Plugins - friends in German
# This file is distributed under the same license as the Plugins - friends package.

The part before the first # is from the redirection template and should not be part of the response.

I was able to workaround this with a regex replace (.replace( /^[^#]+/, '' )) but I believe this should be changed.

adamziel commented 4 months ago

Is this a Playground bug or WordPress bug?