Skip to content

fix(wp-migration): parse table_prefix correctly (v0.0.1.3)#26

Merged
khoipro merged 1 commit into
mainfrom
fix/25-table-prefix-parser
May 2, 2026
Merged

fix(wp-migration): parse table_prefix correctly (v0.0.1.3)#26
khoipro merged 1 commit into
mainfrom
fix/25-table-prefix-parser

Conversation

@khoipro
Copy link
Copy Markdown
Member

@khoipro khoipro commented May 2, 2026

Summary

  • Replaces greedy-sed $table_prefix parser with awk -F"'". The old code returned ; for a normal $table_prefix = 'wp_'; line.
  • Adds empty-check + [A-Za-z0-9_]+ validation since the prefix gets interpolated unquoted into SQL during step 6.
  • Bumps VERSION to 0.0.1.3.

Closes #25.

Verified parsing across formats

$table_prefix = 'wp_';      → wp_
$table_prefix='wpx_';        → wpx_
$table_prefix\t=\t'wp_y';    → wp_y

Test plan

  • bash -n wp-migration.sh passes
  • awk parser tested against 3 whitespace variants
  • Re-run jp1 → sg4 migration — expect log to show real prefix and step 6 to update URL successfully

🤖 Generated with Claude Code

The previous parser used `sed "s/.*'//; s/'.*//"` which is greedy: for
a normal line `$table_prefix = 'wp_';`, the first sed matches up to and
including the closing single-quote, leaving just `;`. This broke step
6 silently — the URL-update query became `SELECT ... FROM ;options`,
mysql errored out under suppressed stderr, and the staging URL never
applied to the destination database.

Switch to `awk -F"'" '/^\$table_prefix[[:space:]]*=/ {print $2; exit}'`
which is robust against whitespace variants and unaffected by the
greedy-matching pitfall. Add empty-check and `[A-Za-z0-9_]+` validation
since the prefix is interpolated unquoted into SQL during step 6.

Bumps VERSION to 0.0.1.3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@khoipro khoipro merged commit cd7dddc into main May 2, 2026
@khoipro khoipro deleted the fix/25-table-prefix-parser branch May 2, 2026 02:09
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.

wp-migration.sh: table_prefix parsed as ';' breaks step-6 URL update

1 participant