Skip to content

Commit

Permalink
Item10520: SEARCH{"SomeName" is now defined as _only_ the form field …
Browse files Browse the repository at this point in the history
…- thank goodness

git-svn-id: http://svn.foswiki.org/trunk/MongoDBPlugin@11830 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Jun 3, 2011
1 parent cb40246 commit 2a0799b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
25 changes: 19 additions & 6 deletions lib/Foswiki/Plugins/MongoDBPlugin/HoistMongoDB.pm
Expand Up @@ -44,12 +44,19 @@ sub hoist {
or MONITOR_DETAIL;

if (not defined($node) or ref( $node->{op} ) eq '') {
if (not defined($node) or Foswiki::Func::isTrue($node->{params}[0])) {
return {};
} else {
#TODO: or return false, or undef?
return {'1' => '0'};
}
return {} if (not defined($node)) ; #undef == true?
return {} if (not defined($node->{params}[0])) ; #undef == true?
return {} if ("$node->{params}[0]" eq '1') ;
return {'1' => '0'} if ("$node->{params}[0]" eq '0') ;
#print STDERR "r($node->{params}[0])".Data::Dumper($node)."\n";
#too naive - a SEARCH{"FieldName" gets tripped up by isTrue :(
#TODO: mmm, maybe use the op-type?
# if (Foswiki::Func::isTrue($node->{params}[0])) {
# return {};
# } else {
# #TODO: or return false, or undef?
# return {'1' => '0'};
# }
}

#TODO: use IxHash to keep the hash order - _some_ parts of queries are order sensitive
Expand All @@ -76,6 +83,7 @@ sub hoist {
}

if ( ref($mongoDBQuery) eq '' ) {
return { '$where' => convertToJavascript($mongoDBQuery) };
#node simplified() to hell?
return { '$where' => $mongoDBQuery };

Expand Down Expand Up @@ -574,6 +582,11 @@ sub convertStringToJS {
sub convertToJavascript {
my $node = shift;
my $statement = '';

if (ref($node) eq '') {
#support annoying incomplete, non-boolean queries like SEARCH{"FieldName"
return convertStringToJS($node);
}

ASSERT( ref($node) eq 'HASH' ) if DEBUG;

Expand Down
16 changes: 14 additions & 2 deletions test/unit/HoistMongoDBsTests.pm
Expand Up @@ -1518,16 +1518,28 @@ sub test_hoist_explicit_true {

#test written to match Fn_SEARCH::verify_formQuery2
#Item10520: in Sven's reading of System.QuerySearch, this should return no results, as there is no field of the name 'TestForm'
sub DISABLEtest_hoist_ImplicitFormNameBUG {
sub test_hoist_ImplicitFormNameBUG {
my $this = shift;
my $s = "FormName";

$this->do_Assert(
$s,

{
'$where' => 'foswiki_getField(this, \'FIELD.FormName.value\')'
}
);
}
#this is just to show that the above eg should be 'ok'
sub test_hoist_ExplicitFormNameCompre {
my $this = shift;
my $s = "FormName = 'qwe'";

$this->do_Assert(
$s,

{
'$where' => '(foswiki_getField(this, \'FIELD.FormName.name\') )'
'FIELD.FormName.value' => 'qwe'
}
);
}
Expand Down

0 comments on commit 2a0799b

Please sign in to comment.