[wp-trac] [WordPress Trac] #26829: Use of strpos() in extract_from_markers() and insert_with_markers() can target wrong BEGIN and END markers.
WordPress Trac
noreply at wordpress.org
Wed Jan 15 03:57:16 UTC 2014
#26829: Use of strpos() in extract_from_markers() and insert_with_markers() can
target wrong BEGIN and END markers.
----------------------------------------+------------------------------
Reporter: Faison | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Rewrite Rules | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests |
----------------------------------------+------------------------------
Comment (by Faison):
Hi Nacin,
I actually need some input on the best way to handle testing
`extract_from_markers()` and `insert_with_markers()`. Since the code uses
the functions `file()`, `fopen()`, etc., we would need to create files
just for the unit tests, create temporary files programmatically within
the tests, or rewrite the functions to use an object that we could mock.
I see that there's a directory for files required for certain unit tests,
but I'm not sure where to put test htaccess files. Also, are the files in
the /phpunit/data/ directory only to be used for read operations? If
that's the case, I start to lean towards wanting to create a temp file
with `tempname()`, but there is a possibility that `tempname()` won't work
on some computers.
Is there a way we can replace the php filesystem calls with an object that
can be mocked? I just found the `WP_Filesystem_Direct` class which has the
function `get_contents_array()` which is just an abstraction for `file()`.
The calls to `fopen`, `fwrite`, and `fclose` in the
`insert_with_markers()` function could be removed by first making changes
into a new array, imploding that array, and passing the resulting string
into the `put_contents()` function.
So what route do you believe would be the best for WordPress and the Test
Suite as a whole?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/26829#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list