Opened 2 years ago
Closed 2 years ago
#633 closed defect (fixed)
Using booleans as string values leads to strange results
| Reported by: | burobjorn@… | Owned by: | mp |
|---|---|---|---|
| Priority: | critical | Milestone: | 3.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!
Attachments (0)
Change History (7)
comment:1 Changed 2 years ago by mp
- Owner changed from mrook to mp
- Status changed from new to assigned
comment:2 Changed 2 years ago by mp
comment:3 Changed 2 years ago by mp
#376 is also related but tried a fix in the ReplaceTokens task?
comment:4 Changed 2 years ago by mp
#383 might also be related
comment:5 Changed 2 years ago by mp
comment:6 Changed 2 years ago by mrook
- Milestone changed from TBD to 2.5.0
comment:7 Changed 2 years ago by mp
- Resolution set to fixed
- Status changed from assigned to closed

Also see #495, might be related