Asciidoctorj: reading the docfile attribute

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Asciidoctorj: reading the docfile attribute

Jeremie Bresson
I have noticed a stange behaviour:

[source,java]
----
parent.getDocument().getAttr("docfile").toString()
----

I get a truncated value of the expected docfile (the last 8 characters)

If I do it like this, I get the complete expected value:

[source,java]
----
    Map<Object, Object> options = parent.getDocument().getOptions();
    for (Object optionKeyObj : options.keySet()) {
      if (optionKeyObj instanceof RubySymbol) {
        if ("attributes".equals(((RubySymbol) optionKeyObj).toJava(String.class))) {
          Object attributesObj = options.get(optionKeyObj);
          if (attributesObj instanceof Map<?, ?>) {
            Map<?, ?> attributes = (Map<?, ?>) attributesObj;
            Object docfile = attributes.get("docfile");
            if (docfile != null) {
              return docfile.toString();
            }
          }
        }
      }
    }
    return null;
----

Tested on window with:
* asciidoctorj.version: 1.5.4
* jruby.version: 1.7.21
* Java 1.7
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj: reading the docfile attribute

mojavelinux
Administrator
Jérémie,

Double check your safe mode. If the safe mode is secure, then the security attempts to truncate the docfile value based on the docdir value. If the docdir value is not a subset of the docfile, you could get weird results.


-Dan

On Tue, Apr 12, 2016 at 9:24 PM, Jeremie Bresson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I have noticed a stange behaviour:

[source,java]
----
parent.getDocument().getAttr("docfile").toString()
----

I get a truncated value of the expected docfile (the last 8 characters)

If I do it like this, I get the complete expected value:

[source,java]
----
    Map<Object, Object> options = parent.getDocument().getOptions();
    for (Object optionKeyObj : options.keySet()) {
      if (optionKeyObj instanceof RubySymbol) {
        if ("attributes".equals(((RubySymbol) optionKeyObj).toJava(String.class))) {
          Object attributesObj = options.get(optionKeyObj);
          if (attributesObj instanceof Map<?, ?>) {
            Map<?, ?> attributes = (Map<?, ?>) attributesObj;
            Object docfile = attributes.get("docfile");
            if (docfile != null) {
              return docfile.toString();
            }
          }
        }
      }
    }
    return null;
----

Tested on window with:
* asciidoctorj.version: 1.5.4
* jruby.version: 1.7.21
* Java 1.7


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctorj-reading-the-docfile-attribute-tp4608.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen