parttio / touchkit

TouchKit is a library of mobile components for Vaadin Framework
https://vaadin.com/directory/component/touchkit
Other
8 stars 11 forks source link

WidgetSet name parsing in TouchKitSettings for Google PWA browsers #18

Closed markusheikkinen closed 6 years ago

markusheikkinen commented 6 years ago

When using TouchKit application with Chrome WidgetSet name parsing fails. Name is parsed using regex

Pattern p = Pattern.compile(".*widgetset\": \"([^\"]+)\"", Pattern.DOTALL);
Matcher matcher = p.matcher(text);
boolean find = matcher.find();
String wsname = matcher.group(1);

There is space after colon. This fails on getting group(1) from matcher when application is in production mode. Response data contains then "versionInfo":{"vaadinVersion":"8.4.2"},"widgetset":"com....WidgetSet"

In development mode the response is formatted and there is space after colon and name parsing works ok. Line-breaks are removed before regex handling (with TODO comments).

"versionInfo": {
  "vaadinVersion": "8.4.2"
  },
  "widgetset": "com...WidgetSet"
mstahv commented 6 years ago

Do you have a suggestion to enhance the regexp?

markusheikkinen commented 6 years ago

If space after "widgetset:" is optional then regexp could be changed by adding optional whitespace character (\s?) to pattern. When I tried with simple test-class I had to include .* at the end of regexp.

Pattern p = Pattern.compile(".*widgetset\":\\s?\"([^\"]+)\".*", Pattern.DOTALL);

This is what I was writing yesterday but noticed that you already closed the issue with a change that allows whitespaces, Thanks.

mstahv commented 6 years ago

Yep, cutting a release right now.

markusheikkinen commented 6 years ago

Now this works with production mode as well as in debug mode, at least in our test project.