-
Notifications
You must be signed in to change notification settings - Fork 268
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
importWxr: Preserve backslashes in the imported content #1213
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/playground/blueprints/src/lib/steps/fixtures/import-wxr-slash-issue.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<rss version="2.0" | ||
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" | ||
xmlns:content="http://purl.org/rss/1.0/modules/content/" | ||
xmlns:wfw="http://wellformedweb.org/CommentAPI/" | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:wp="http://wordpress.org/export/1.2/" | ||
> | ||
|
||
<channel> | ||
<title>My WordPress Website</title> | ||
<link>https://playground.wordpress.net/scope:0.6224554755515266</link> | ||
<description></description> | ||
<pubDate>Mon, 08 Apr 2024 07:03:05 +0000</pubDate> | ||
<language>en-US</language> | ||
<wp:wxr_version>1.2</wp:wxr_version> | ||
<wp:base_site_url>https://playground.wordpress.net/scope:0.6224554755515266</wp:base_site_url> | ||
<wp:base_blog_url>https://playground.wordpress.net/scope:0.6224554755515266</wp:base_blog_url> | ||
|
||
<wp:author><wp:author_id>1</wp:author_id><wp:author_login><![CDATA[admin]]></wp:author_login><wp:author_email><![CDATA[admin@localhost.com]]></wp:author_email><wp:author_display_name><![CDATA[admin]]></wp:author_display_name><wp:author_first_name><![CDATA[]]></wp:author_first_name><wp:author_last_name><![CDATA[]]></wp:author_last_name></wp:author> | ||
|
||
|
||
<generator>https://wordpress.org/?v=6.5</generator> | ||
|
||
<item> | ||
<title><![CDATA["Issue\Issue"]]></title> | ||
<link>https://playground.wordpress.net/scope:0.6224554755515266/?p=5</link> | ||
<pubDate>Mon, 08 Apr 2024 06:59:36 +0000</pubDate> | ||
<dc:creator><![CDATA[admin]]></dc:creator> | ||
<guid isPermaLink="false">https://playground.wordpress.net/scope:0.6224554755515266/?p=5</guid> | ||
<description></description> | ||
<content:encoded><![CDATA[<!-- wp:inseri-core/text-editor {"blockId":"DSrQIjN5UjosCHJQImF5z","blockName":"textEditor","height":60,"content":"\u0022#test\u0022","contentType":"application/json"} --> | ||
<div class="wp-block-inseri-core-text-editor" data-attributes="{"blockId":"DSrQIjN5UjosCHJQImF5z","blockName":"textEditor","content":"\"#test\"","contentType":"application/json","editable":false,"height":60,"isVisible":true,"label":""}">is loading ...</div> | ||
<!-- /wp:inseri-core/text-editor -->]]></content:encoded> | ||
<excerpt:encoded><![CDATA[]]></excerpt:encoded> | ||
<wp:post_id>5</wp:post_id> | ||
<wp:post_date><![CDATA[2024-04-08 06:59:36]]></wp:post_date> | ||
<wp:post_date_gmt><![CDATA[2024-04-08 06:59:36]]></wp:post_date_gmt> | ||
<wp:post_modified><![CDATA[2024-04-08 07:02:42]]></wp:post_modified> | ||
<wp:post_modified_gmt><![CDATA[2024-04-08 07:02:42]]></wp:post_modified_gmt> | ||
<wp:comment_status><![CDATA[open]]></wp:comment_status> | ||
<wp:ping_status><![CDATA[open]]></wp:ping_status> | ||
<wp:post_name><![CDATA[issue]]></wp:post_name> | ||
<wp:status><![CDATA[publish]]></wp:status> | ||
<wp:post_parent>0</wp:post_parent> | ||
<wp:menu_order>0</wp:menu_order> | ||
<wp:post_type><![CDATA[post]]></wp:post_type> | ||
<wp:post_password><![CDATA[]]></wp:post_password> | ||
<wp:is_sticky>0</wp:is_sticky> | ||
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category> | ||
<wp:postmeta> | ||
<wp:meta_key><![CDATA[_pingme]]></wp:meta_key> | ||
<wp:meta_value><![CDATA[1]]></wp:meta_value> | ||
</wp:postmeta> | ||
<wp:postmeta> | ||
<wp:meta_key><![CDATA[_encloseme]]></wp:meta_key> | ||
<wp:meta_value><![CDATA[1]]></wp:meta_value> | ||
</wp:postmeta> | ||
</item> | ||
</channel> | ||
</rss> |
76 changes: 76 additions & 0 deletions
76
packages/playground/blueprints/src/lib/steps/import-wxr.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { NodePHP } from '@php-wasm/node'; | ||
import { | ||
RecommendedPHPVersion, | ||
getWordPressModule, | ||
} from '@wp-playground/wordpress'; | ||
import { importWxr } from './import-wxr'; | ||
import { readFile } from 'fs/promises'; | ||
import { unzip } from './unzip'; | ||
import { installPlugin } from './install-plugin'; | ||
|
||
describe('Blueprint step importWxr', () => { | ||
let php: NodePHP; | ||
beforeEach(async () => { | ||
php = await NodePHP.load(RecommendedPHPVersion, { | ||
requestHandler: { | ||
documentRoot: '/wordpress', | ||
}, | ||
}); | ||
|
||
await unzip(php, { | ||
zipFile: await getWordPressModule(), | ||
extractToPath: '/wordpress', | ||
}); | ||
|
||
// Delete all posts | ||
await php.run({ | ||
code: `<?php | ||
require '/wordpress/wp-load.php'; | ||
$posts = get_posts(); | ||
foreach ($posts as $post) { | ||
wp_delete_post($post->ID, true); | ||
} | ||
`, | ||
}); | ||
|
||
// Install the WordPress importer plugin | ||
const pluginZipData = await readFile( | ||
__dirname + '/../../../../website/public/wordpress-importer.zip' | ||
); | ||
const pluginZipFile = new File([pluginZipData], 'plugin.zip'); | ||
await installPlugin(php, { | ||
pluginZipFile, | ||
}); | ||
}); | ||
|
||
it('Should import a WXR file with JSON-encoded UTF-8 characters', async () => { | ||
const fileData = await readFile( | ||
__dirname + '/fixtures/import-wxr-slash-issue.xml' | ||
); | ||
const file = new File([fileData], 'import.wxr'); | ||
|
||
await importWxr(php, { file }); | ||
|
||
const expectedPostContent = `<!-- wp:inseri-core/text-editor {"blockId":"DSrQIjN5UjosCHJQImF5z","blockName":"textEditor","height":60,"content":"\\u0022#test\\u0022","contentType":"application/json"} --> | ||
<div class="wp-block-inseri-core-text-editor" data-attributes="{"blockId":"DSrQIjN5UjosCHJQImF5z","blockName":"textEditor","content":"\\"#test\\"","contentType":"application/json","editable":false,"height":60,"isVisible":true,"label":""}">is loading ...</div> | ||
<!-- /wp:inseri-core/text-editor -->`; | ||
|
||
const result = await php.run({ | ||
code: `<?php | ||
require getenv('DOCROOT') . '/wp-load.php'; | ||
$posts = get_posts(); | ||
echo json_encode([ | ||
'post_content' => $posts[0]->post_content, | ||
'post_title' => $posts[0]->post_title, | ||
]); | ||
`, | ||
env: { | ||
DOCROOT: await php.documentRoot, | ||
}, | ||
}); | ||
const json = result.json; | ||
|
||
expect(json.post_content).toEqual(expectedPostContent); | ||
expect(json.post_title).toEqual(`"Issue\\Issue"`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
given that these are encoding tests, I could see some value in storing this in a file as well. it seems like you properly encoded
\\u0022
so that it turns into\u0022
, but it's easy to get lost quickly in the levels of encoding and displayThere 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.
Aha, that's a good point!