Repository navigation
hasmember: one rule in field_search, as in DID-matlab (#236) - #108
Merged
Merged
Conversation
…ab#236)
DID-matlab put a text 'hasmember' value into its SQL unquoted. Python never
builds SQL for hasmember (_query_struct_to_sql_str returns None and the term
is brute-forced with field_search), so its search was never affected.
tests/test_hasmember_quoting.py mirrors DID-matlab's TestHasMemberQuoting:
text values ('value', '1 OR 1=1', values holding " and '), numbers and
~hasmember, alone, inside an AND and inside an OR, compared with field_search
and with the documents DID-matlab finds. It found that field_search never
matched a number stored as a scalar (5 in 5 is a TypeError) where MATLAB's
ismember(5, 5) does; field_search now compares a scalar with ==.
Bridge: database matlab_last_sync_hash -> c8adf741 with a decision_log note
(did/database.py does not change), and a fieldsearch note.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C7XsYS2DKSy2ucFzEEWR3D
…ting Bridge: database matlab_last_sync_hash -> 2c08472c, the DID-matlab merge of main (#237, 2c9d8fa7) into the #236 branch; both decision_log notes kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7XsYS2DKSy2ucFzEEWR3D
…er-quoting #109 merged the database entry's two decision_log keys into one. The #236 note and the 2c08472c merge note move to the end of that merged block; matlab_last_sync_hash stays 2c08472c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7XsYS2DKSy2ucFzEEWR3D
DID-matlab f4ed409e gives fieldsearch and its SQL search one hasmember rule; field_search now matches it too (_has_member): text is a member of text that is the whole value or an item of its comma-separated list, anything of a list holding an equal element, a number of an equal number; text never of a number, nor a number of text; a dict has no members. Before, `in` tested text for a substring and dict keys. test_hasmember_quoting.py: test_rule runs the table of DID-matlab's TestHasMemberQuoting/testRule; new cases for text vs. numbers and a struct field. Bridge: database and fieldsearch matlab_last_sync_hash -> f4ed409e, with their decision_log notes rewritten for the shared rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7XsYS2DKSy2ucFzEEWR3D
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7XsYS2DKSy2ucFzEEWR3D
DID-matlab 74ae15f1 searches hasmember by brute force with fieldsearch, as SQLiteDB always has, so neither did/database.py nor sqlitedb.py changes. database matlab_last_sync_hash -> 74ae15f1, its decision_log note rewritten. test_hasmember_quoting.py adds the cases brute force now covers in both languages: a missing field and list-valued fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7XsYS2DKSy2ucFzEEWR3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Counterpart of VH-Lab/DID-matlab#239 (fixes VH-Lab/DID-matlab#236). Merge DID-matlab#239 first, with a merge commit, so the hashes recorded here stay on DID-matlab
main.Background
hasmembervalue into its SQL unquoted, so'value'matched every document and'1 OR 1=1'was SQL injection.doc2sqlstores as'[1 3] double'.hasmembermeant something different in each place:fieldsearchusedismember, which compares texts character by character.field_searchusedin: a substring test, dict keys, and aTypeError(no match) on a scalar number.DID-matlab#239 gives
fieldsearchone rule and makes MATLAB searchhasmemberby brute force withfieldsearch, asSQLiteDBhere always has (_query_struct_to_sql_strreturnsNonefor it). The two languages now apply the same rule the same way. This PR is the Python side.Changes
src/did/datastructures.py:field_search'shasmembercalls a new_has_member:(^|,\s*)M\s*(,|$))tests/test_hasmember_quoting.py(new):test_ruleruns the same 19-case table as DID-matlab'sTestHasMemberQuoting/testRule, each case also negated.'value','1 OR 1=1', values with"and','5',''), numbers including Inf/NaN,~hasmember, text vs. numbers, a struct field, a missing field, list-valued fields, and each inside an AND and an OR. Each search is compared withfield_searchand with the documents DID-matlab finds.database:matlab_last_sync_hash→74ae15f1. Thedecision_lognote coversc8adf741..74ae15f1, the DID-matlab brute-force switch (isBruteForceTerm), and the2c08472cmerge of DID-matlab main (#237). Neitherdid/database.pynordid/implementations/sqlitedb.pychanges.fieldsearch:matlab_last_sync_hash051f535→f4ed409e, the only commit touchingfieldsearch.msince051f535. The note records the shared rule.This branch has
mainmerged in, including #107 (the #237 port) and #109 (onedecision_logper entry).Checks run locally
black --check src tests: clean (pinned 26.5.1)ruff check src tests: clean (pinned 0.16.5)pytest: 857 passed, 10 skipped, 1 xfailedbin/check_bridge_coverage.py --check file|hash|status|drift|member|missingagainst a non-shallow DID-matlab checkout at74ae15f1: 0 problems each🤖 Generated with Claude Code
https://claude.ai/code/session_01C7XsYS2DKSy2ucFzEEWR3D