Ticket #633 (closed defect: fixed)
Using booleans as string values leads to strange results
| Reported by: | burobjorn@… | Owned by: | mp |
|---|---|---|---|
| Priority: | critical | Milestone: | 2.5.0 |
| Component: | phing-core | Version: | 2.4.4 |
| Keywords: | regex, boolean | Cc: |
Description
I'm using a ReplaceRegexp filter to change WordPress' wp-config.php file. In this file a constant WP_DEBUG is defined false and I would to change it to true. I have defined the regex and provided a property with a string "true". However this string will be casted to a bool and causes strange sideeffects.
Consider this build.xml example:
<property name="wp_config.wp_debug" value="true" />
<target name="setup-wp-config" description="Copies the wp-config-sample.php to wp-config.php and sets up the parameters for the audition test site">
<copy file="./wp-config-sample.php" tofile="./wp-config.php">
<filterchain>
<replaceregexp>
<regexp pattern="(define\('WP_DEBUG', )\w+(\);)" replace="\1${wp_config.wp_debug}\2"/>
</replaceregexp>
</filterchain>
</copy>
</target>
If you would run this it would not work as expected. Changing the property to "foo" it does work as expected. This is probably related to this thread:
http://phing.tigris.org/ds/viewMessage.do?dsForumId=1083&dsMessageId=958537
Using the workaround in the thread the example becomes:
<property name="wp_config.wp_debug" value="(bool)true" />
<target name="setup-wp-config" description="Copies the wp-config-sample.php to wp-config.php and sets up the parameters for the audition test site">
<copy file="./wp-config-sample.php" tofile="./wp-config.php">
<filterchain>
<replaceregexp>
<regexp pattern="(define\('WP_DEBUG', )\w+(\);)" replace="\1${wp_config.wp_debug}\2"/>
</replaceregexp>
</filterchain>
</copy>
</target>
Thus by adding the type (bool) forces Phing to work correctly with boolean values as strings. Thanks Hans Lellelid for this workaround!
