iheartradio / open-m3u8

Open Source m3u8 Parser
Other
248 stars 94 forks source link

Spaces in TARGETDURATION and MEDIA-SEQUENCE tags #28

Open ketankhairnar opened 8 years ago

ketankhairnar commented 8 years ago

I've observed spaces in generated m3u8 from CDNs for these tags. Note the space after colon. Do we need to handle this as part of library? Spec doesn't say whether space is allowed.

should be #EXT-X-TARGETDURATION:<s>  but seen as #EXT-X-TARGETDURATION: <s>
should be #EXT-X-MEDIA-SEQUENCE:<number> but seen as #EXT-X-MEDIA-SEQUENCE: <number>

For now I've handled with below change in Constants.java.

public static final Pattern EXT_X_TARGETDURATION_PATTERN = Pattern.compile("^#" + EXT_X_TARGETDURATION_TAG + EXT_TAG_END + OPTIONAL_WHITESPACE_REGEX +"(" + INTEGER_REGEX + ")"+OPTIONAL_WHITESPACE_REGEX+"$");
public static final Pattern EXT_X_MEDIA_SEQUENCE_PATTERN = Pattern.compile("^#" + EXT_X_MEDIA_SEQUENCE_TAG + EXT_TAG_END + OPTIONAL_WHITESPACE_REGEX +"(" + INTEGER_REGEX + ")"+OPTIONAL_WHITESPACE_REGEX+"$");

Where regex for optional white space is as below

private static final String OPTIONAL_WHITESPACE_REGEX = "\\s*?";

Let me know if this makes sense. There is no harm if no spaces exist. regex takes care of that case too.

Wopple commented 8 years ago

The regexes look good. I would add an allowWhitespaceInTags flag in ParsingMode and set it to true for the LENIENT constant. At this point I'm considering making LENIENT the default.

ketankhairnar commented 8 years ago

While default LENIENT mode seems easy option with allowWhitespaceInTags set to true; Am wondering when would need STRICT parsing mode.

Let me know when can this be added? you need any PR for this?

derjust commented 8 years ago

You would need strict for non-forgiving M3u8 consumers (So far I haven't seen any - usually they are all very forgiving)