View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0009317 | CMake | CMake | public | 2009-07-27 04:11 | 2016-06-10 14:30 | ||||
Reporter | Tomasz Majchrowski | ||||||||
Assigned To | Bill Hoffman | ||||||||
Priority | normal | Severity | minor | Reproducibility | always | ||||
Status | closed | Resolution | moved | ||||||
Platform | OS | OS Version | |||||||
Product Version | |||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0009317: When the single bracket present in the data field of the list the length statment return incorrect value | ||||||||
Description | When the single bracket (e.g. open or closed) present in the data field of the list the length (but probably also other list management statements) return incorrect number of the elements. | ||||||||
Additional Information | The following peace of code could be used to demonstrate the problem: cmake_minimum_required( VERSION 2.6 ) set (_list) list(APPEND _list "foo" "bar")0000002 items list (LENGTH _list _len) message (STATUS "_len=${_len}")# 2 set (_list) list(APPEND _list "foo[]" "bar")0000002 items list (LENGTH _list _len) message (STATUS "_len=${_len}")# 2 set (_list) list(APPEND _list "foo]" "bar")0000002 items list (LENGTH _list _len) message (STATUS "_len=${_len}")#1 | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | FixSquareBracketsInLists.patch [^] (673 bytes) 2013-02-25 10:46 [Show Content] | ||||||||
Relationships | |
Relationships |
Notes | |
(0028077) Erik Hasslmeyer (reporter) 2011-12-29 21:31 |
This bug is worse than stated here, becauase foreach() is affected by this bug, too: cmake_minimum_required(VERSION 2.8) set(myList a b [ c d) foreach(myElem ${myList}) message(${myElem}) endforeach() return() This displays a b [;c;d instead of a b [ c d So every time you iterate over a list the iteration will fail if the input data contains a square bracket. => Target property SOURCES is problematic if one path of a source file contains a square bracket. => Using "file(STRINGS ...)" to parse a file is rather useless if the extracted data contains only a single square bracket. ... |
(0028078) Erik Hasslmeyer (reporter) 2011-12-30 07:22 |
I looked at the source code and apparently this behavior was supposed to be a feature called "squareNesting" with the sole purpose of escaping semicolons when expanding lists. The code for list expansion is here "cmSystemTools::ExpandListArgument(...)" and it does this: - Semicolons between [] do not split the list (To be precise: If a semicolon has the same number of opening and closing square brackets to the left then the list is splitted. Otherwise it is not.) - Semicolons that are preceded by a backslash do not split the list. List expansion is used this way: 1. Whenever a command is invoked that gets a ${somelist} as parameter then the "ExpandListArgument" method is called in order to expand the lists contents. (see cmCommand::InvokeInitialPass) 2. The list command uses the "ExpandListArgument" method to expand the list that is passed as argument (see cmListCommand::GetList) The first case causes the foreach bug, the second one the list(LENGTH ...) bug. Conclusion: In my opinion this is very serious, because it makes argument passing with lists very unreliable. The problem is how to fix this bug. As far as i can tell there are several possibilities: 1. Remove this "squareNesting" feature. 2. Keep it as is and update the documentation with a big warning 3. Implement it properly I'd vote for the first solution, because this feature is really screwed up: - The square brackets themselves are not removed when used to escape semicolons - It is not possible to escape the square brackets, so you simply can't use square brackets in lists. - Implementing it properly is hard (probably impossible) - I'd also remove the escape of the semicolon, because a list with the folowing content would also screw up list expansion: "C:\mydir1\;C:\mydir2\" I looked at the source code of 2.8.4 and 2.8.6. |
(0032112) corneliup (reporter) 2013-01-17 08:49 |
This bug has an impact also when a list containing square brackets is used as a COMMAND parameter. This is needed in many cases when Linux bash commands must be run as COMMAND parameters, since square brackets are used as conditional operator separators: Example: if a command is set to contain the following bash command set(MY_CMD if [ -f test.txt ] "\\;" then echo \"File test.txt found\" "\\;" else echo \"File test.txt NOT found\" "\\;" fi) there is no easy way for adding a target with the above commands add_custom_target ( test COMMAND ${MY_CMD1} WORKING_DIRECTORY ${WORK_DIR} ) Please advice on possible workarounds. Would it also be possible to upgrade the severity, taking into account the fact that all Linux users are potentially impacted? |
(0032377) Andreas Stahl (reporter) 2013-02-25 10:47 |
I'm also affected by this bug, as I am trying to configure files that expect funky version checking syntax with inclusive and exclusive interval limits i.e. [1.0, 2.0) = all versions from 1.0 up to excluding 2.0 If the squareNesting feature is really desired and actively used, I would rather lean towards another option: allowing square brackets to be properly escape-handled like the ';', since they are effectively also list control characters otherwise. I added a patch that does exactly that, now double backslashes will escape square brackets without errors (single backslashes will generate developer warnings, as \[ is apparently not a valid escape sequence in cmake). |
(0040722) David Cole (manager) 2016-03-18 09:16 |
This StackOverflow answer indicates some Windows-only registry [key;value] pair behavior which anyone who attempts to fix this bug will have to take into account. http://stackoverflow.com/a/36085151/236192 [^] |
(0041580) Kitware Robot (administrator) 2016-06-10 14:27 |
Resolving issue as `moved`. This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
2009-07-27 04:11 | Tomasz Majchrowski | New Issue | |
2009-09-14 12:24 | Bill Hoffman | Status | new => assigned |
2009-09-14 12:24 | Bill Hoffman | Assigned To | => Bill Hoffman |
2011-12-29 21:31 | Erik Hasslmeyer | Note Added: 0028077 | |
2011-12-30 07:22 | Erik Hasslmeyer | Note Added: 0028078 | |
2013-01-17 08:49 | corneliup | Note Added: 0032112 | |
2013-02-25 10:46 | Andreas Stahl | File Added: FixSquareBracketsInLists.patch | |
2013-02-25 10:47 | Andreas Stahl | Note Added: 0032377 | |
2016-03-18 09:16 | David Cole | Note Added: 0040722 | |
2016-06-10 14:27 | Kitware Robot | Note Added: 0041580 | |
2016-06-10 14:27 | Kitware Robot | Status | assigned => resolved |
2016-06-10 14:27 | Kitware Robot | Resolution | open => moved |
2016-06-10 14:30 | Kitware Robot | Status | resolved => closed |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |