daisy / pipeline-webui

A Web User Interface for the DAISY Pipeline 2
Other
3 stars 2 forks source link

Validation problem with Transformer query field #117

Closed egli closed 6 years ago

egli commented 6 years ago

I'm running the pipeline and the webui using the latest docker images with docker-compose. Basically I just run docker-compose up with https://github.com/daisy/pipeline-webui/blob/feature/dockercompose/docker-compose.yml

When I try to run the DTBook to PEF script I get a warning from the UI that the Transformer query field is not valid and consequently I cannot submit my job.

it contains (translator:liblouis)(formatter:dotify) (the default basically). That seems to be correct.

@bertfrees says that it should match the following regexp: ^\s*(\(\s*[_a-zA-Z][_a-zA-Z0-9-]*(\s*\:\s*([_a-zA-Z][_a-zA-Z0-9-]*|'[^']*'|"[^"]*"|0|-?[1-9][0-9]*))?\s*\)\s*)*$

According to Bert the following info is also relevant:

docker run -d --rm --name pipeline2 -p 8181:8181 --env PIPELINE2_AUTH=false --env PIPELINE2_LOCAL=false --env PIPELINE2_HOST=0.0.0.0 daisyorg/pipeline2
8b5092a47392c2e08d52b330c6d1e3f2e59be5d525dafea3e0ce4a83377fdd11
eglic@wharton:~/src/pipeline-assembly$ curl http://localhost:8181/ws/datatypes/transform-query
<?xml version="1.0" encoding="UTF-8" standalone="no"?><data id="transform-query" type="string">
    <documentation xml:lang="en">A query

The syntax is as follows (described in terms of [CSS grammar](https://www.w3.org/TR/CSS21/grammar.html)):

    query
     : feature*
     ;
    feature
     : '(' S* IDENT S* [ ':' S* value ]? ')' S*
     ;
    value
     : string | integer | IDENT
     ;
</documentation>
    <param name="pattern">^\s*(\(\s*[_a-zA-Z][_a-zA-Z0-9-]*(\s*\:\s*([_a-zA-Z][_a-zA-Z0-9-]*|'[^']*'|"[^"]*"|0|-?[1-9][0-9]*))?\s*\)\s*)*$</param>
</data>

This seems to indicate that the problem is not with the pipeline but rather as @bertfrees says

must be a problem in the web UI then

Any ideas?

josteinaj commented 6 years ago

I've found the problem. I'm not sure whether or not to blame the Web UI though.

The regex is defined here (i.e. the same snippet as yours above): https://github.com/daisy/pipeline-mod-braille/blob/51d8a1321ae6503ba988c4a1e716fe918b3d3b39/pipeline-braille-utils/common-utils/src/main/resources/xml/data-types/transform-query.xml#L17

In the regex, the : is escaped as \:. This is not necessary, and when used on a pattern attribute in a modern web browser, it will give an error. I believe it is the same error as is described here: https://www.fxsitecompat.com/en-CA/docs/2016/input-pattern-now-sets-u-flag-for-regular-expressions/ which says that the error is because ECMAScript 6 does not allow any arbitrary character to be escaped: https://tc39.github.io/ecma262/#sec-regexp-regular-expression-objects

It's weird though; I can create a Javascript regex object with p = /.../; without getting any errors, but when I put it in a <input pattern="..."/>, I get the regex validation error in the console. Anyhoo...

Instead of the Web UI trying to clean up regexes, I suggest that regexes should not contain escaped characters that doesn't need to be escaped. So instead we should fix the regex in the braille common-utils.

@bertfrees @egli what do you think?

bertfrees commented 6 years ago

Cool. Yeah I guess we can remove the backslash.

josteinaj commented 6 years ago

Closing this as we're not doing anything about it in the Web UI.