Jabref: regexp search throws exception when entering slash

Created on 23 Aug 2020  路  16Comments  路  Source: JabRef/jabref

JabRef 5.1--2020-08-22--dc55a76
Linux 5.4.19-050419-generic amd64
Java 14.0.2

  • [x] Mandatory: I have tested the latest development version from http://builds.jabref.org/master/ and the problem persists

Steps to reproduce the behavior:

  1. Open bib file
  2. Switch to regexp search
  3. Enter something with a "/" in it, e.g. bla/bla
  4. For each matching entry you get an exception (see details below) thrown. I had once about 50 results, so 50 windows with an exception trace opened.

Maybe the regular expression could be checked and an exclamation mark icon shown as long as it is incomplete or not escaped before it's executed. Or, one could employ some automatic escaping.


Log File

netscape.javascript.JSException: SyntaxError: Invalid regular expression: missing )
at [email protected]/com.sun.webkit.dom.JSObject.fwkMakeException(Unknown Source)
at [email protected]/com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at [email protected]/com.sun.webkit.WebPage.executeScript(Unknown Source)
at [email protected]/javafx.scene.web.WebEngine.executeScript(Unknown Source)
at [email protected]/org.jabref.gui.preview.PreviewViewer.highlightSearchPattern(Unknown Source)
at [email protected]/org.jabref.gui.preview.PreviewViewer.lambda$new$0(Unknown Source)
at [email protected]/com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(Unknown Source)
at [email protected]/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown Source)
at [email protected]/javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(Unknown Source)
at [email protected]/javafx.beans.property.ObjectPropertyBase.markInvalid(Unknown Source)
at [email protected]/javafx.beans.property.ObjectPropertyBase.set(Unknown Source)
at [email protected]/javafx.beans.property.ObjectProperty.setValue(Unknown Source)
at [email protected]/org.jabref.gui.StateManager.setSearchQuery(Unknown Source)
at [email protected]/org.jabref.gui.search.GlobalSearchBar.performSearch(Unknown Source)
at [email protected]/org.reactfx.util.FxTimer.lambda$restart$0(Unknown Source)
at [email protected]/com.sun.scenario.animation.shared.TimelineClipCore.visitKeyFrame(Unknown Source)
at [email protected]/com.sun.scenario.animation.shared.TimelineClipCore.playTo(Unknown Source)
at [email protected]/javafx.animation.Timeline.doPlayTo(Unknown Source)
at [email protected]/javafx.animation.AnimationAccessorImpl.playTo(Unknown Source)
at [email protected]/com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(Unknown Source)
at [email protected]/javafx.animation.Animation.doTimePulse(Unknown Source)
at [email protected]/javafx.animation.Animation$1.lambda$timePulse$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at [email protected]/javafx.animation.Animation$1.timePulse(Unknown Source)
at [email protected]/com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(Unknown Source)
at [email protected]/com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(Unknown Source)
at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(Unknown Source)
at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(Unknown Source)
at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at [email protected]/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)

entry-preview search bug 馃悰

Most helpful comment

Ah yes you are right regarding the simple search. Overlooked that.
You might want to ask @tobiasdiez what he did there 4 years ago :-P
https://github.com/JabRef/jabref/pull/1995

Edit// I think your approach seems to be correct. I looked at that, that does make indeed more sense

All 16 comments

Thanks for the report. From the log it seems like an error in the highlighting script for the entry preview.

I just realised I don't know how the regexp search is supposed to work.... Is it correct that regexp should only works for fields (e.g., citationkey = Turing\d[0-9]*) which in turn does not get highlighted in the preview?

Right now, if I were to search for Turing\d[0-9]* everything contained in a preview matching the regexp would be highlighted, while only entries containing a literal match would be shown in the search results. Have I missed something?

Regarding the search, have you enabled the regex mode?
https://docs.jabref.org/finding-sorting-and-cleaning-entries/search#regular-expressions-and-casing
(the search is actually based on an Antlr4 grammar, you find that in buildres)

The highlight function is pretty simple, it does not work with JabRef's search grammar. It's just for highlighting search words.
It's based on https://markjs.io/

I believe so 馃槵
Note the "no results found".

Ska虉rmavbild 2020-11-04 kl  16 32 47

I have ogled Antlr4 a bit, the issue is that I don't know what should happen. In my opinion, the search shown above should return some result.

Preventing the exception can either be done by escaping the slash or using new RegExp (which is what I tried out in #7073).

You are right that should show results.
try Debugging if the correct mode is correctly activated (class is GlobalSearchBar)
Might also be an issue with multiple open libraries. That can cause quirks

Ok, in that case I will include it in the PR for this issue.

@k3KAW8Pnf7mkmdSMPHz27 I did a quick test and it seems like the regex search only works in combination with a field:
e.g. author=Liu.*
See:
https://github.com/JabRef/jabref/blob/4e220f618a755cb7dc18882653ea46e3ed049c9e/src/main/java/org/jabref/model/search/rules/SearchRules.java#L7

@Siedlerchr as far as I can tell that is the case. Note that Liu.* is a GrammarBasedSearchRule. I am using a break-point at https://github.com/JabRef/jabref/blob/4e220f618a755cb7dc18882653ea46e3ed049c9e/src/main/java/org/jabref/model/search/rules/SearchRules.java#L16
while debugging.

But, right now I believe
https://github.com/JabRef/jabref/blob/fcbe9c52e099a783a67b1445e2b9bb6f4c485fa0/src/main/java/org/jabref/model/search/rules/GrammarBasedSearchRule.java#L235
should be using
https://github.com/JabRef/jabref/blob/4e220f618a755cb7dc18882653ea46e3ed049c9e/src/main/java/org/jabref/model/search/rules/SearchRules.java#L34

However, my experience of debugging Antlr consists of this issue 馃榾
I'll put some more time into this and see if I can find the "correct" solution.

Ah yes you are right regarding the simple search. Overlooked that.
You might want to ask @tobiasdiez what he did there 4 years ago :-P
https://github.com/JabRef/jabref/pull/1995

Edit// I think your approach seems to be correct. I looked at that, that does make indeed more sense

Please don't put much energy in the ANTLR code. It is obsolete and should be replaced by Lucene: https://github.com/JabRef/jabref/issues/1975

@Siedlerchr @tobiasdiez Ok, in that case I will try to "patch" the issue(s) rather than delving deeper into it.

I think you just need to add and addtional if check for regex and then call either the regex rule or the contains. That looks like the simples way
https://github.com/JabRef/jabref/blob/4e220f618a755cb7dc18882653ea46e3ed049c9e/src/main/java/org/jabref/model/search/rules/GrammarBasedSearchRule.java#L234-L235

@ytzemih Thanks to @k3KAW8Pnf7mkmdSMPHz27 this issue is now fixed. We also fxed another issue where regex search did not find some entries

@Siedlerchr @k3KAW8Pnf7mkmdSMPHz27 Nice to hear. Thanks for the effort. Will try it out as soon as it is in the build.

The new dev version should be already avaiable.

@Siedlerchr Brilliant, just downloaded it, tried it, and it seems to work properly for me. Thanks, again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LinusDietz picture LinusDietz  路  3Comments

Braunch picture Braunch  路  3Comments

JoKalliauer picture JoKalliauer  路  3Comments

thorstenwagner picture thorstenwagner  路  4Comments

humbleambition picture humbleambition  路  3Comments