@@ -138,13 +138,51 @@ function clauseMatches(version, clause) {
138138 ) ;
139139 }
140140 const d = compareVersions ( version , operand ) ;
141- return op === "<"
142- ? d < 0
143- : op === "<="
144- ? d <= 0
145- : op === ">"
146- ? d > 0
147- : d >= 0 ;
141+ if ( op === "<" ) return d < 0 && ! isPreOf ( version , operand ) ;
142+ if ( op === ">" ) return d > 0 && ! isPostOf ( version , operand ) ;
143+ return op === "<=" ? d <= 0 : d >= 0 ;
144+ }
145+
146+ /** Same epoch and release, compared with trailing zeros ignored. */
147+ function sameRelease ( a , b ) {
148+ return compareVersions ( releaseOnly ( a ) , releaseOnly ( b ) ) === 0 ;
149+ }
150+
151+ function releaseOnly ( v ) {
152+ const { epoch, release } = parseVersion ( v ) ;
153+ return `${ epoch } !${ release . join ( "." ) } ` ;
154+ }
155+
156+ /**
157+ * PEP 440's exclusive `<V` "MUST NOT allow a pre-release of the specified
158+ * version unless the specified version is itself a pre-release": `<2.0`
159+ * excludes `2.0rc1`, which sorts below it.
160+ */
161+ function isPreOf ( version , operand ) {
162+ const v = parseVersion ( version ) ;
163+ const o = parseVersion ( operand ) ;
164+ return (
165+ ( v . pre !== null || v . dev !== null ) &&
166+ o . pre === null &&
167+ o . dev === null &&
168+ sameRelease ( version , operand )
169+ ) ;
170+ }
171+
172+ /**
173+ * PEP 440's exclusive `>V` "MUST NOT allow a post-release of the given
174+ * version unless V itself is a post release": `>1.0` excludes `1.0.post1`,
175+ * which sorts above it.
176+ */
177+ function isPostOf ( version , operand ) {
178+ const v = parseVersion ( version ) ;
179+ const o = parseVersion ( operand ) ;
180+ return (
181+ v . post !== null &&
182+ o . post === null &&
183+ sameRelease ( version , operand ) &&
184+ JSON . stringify ( v . pre ) === JSON . stringify ( o . pre )
185+ ) ;
148186}
149187
150188/**
0 commit comments